@LabelIndex 33121
@StringIndex 0
class 0 ssq_event_party_leader : ssq_party_leader {
parameter:
	int	DDMagic = 264241153;

handler:
	EventHandler CREATED(i0) {
		myself.sm.flag = myself.sm.param1;
		i0 = ( ( 60 * 5 ) - ( myself::GetCurrentTick() - myself.sm.param2 ) );
		if( i0 < 1 ) {
			myself::Despawn();
			return;
		}
		myself::AddTimerEx(2000,( i0 * 1000 ));
		myself::AddTimerEx(2002,5000);
		super;
	}

	EventHandler SEE_CREATURE(creature) {
		if( myself.p_state != 3 ) {
			if( creature.is_pc == 0 && myself::IsInCategory(12,creature.class_id) == 0 ) {
				return;
			}
			if( myself::GetLifeTime() > SeeCreatureAttackerTime && myself::InMyTerritory(myself.sm) ) {
				myself::AddAttackDesire(creature,1,200);
			}
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id) {
		if( timer_id == 2000 ) {
			if( myself.p_state != 3 ) {
				myself::Despawn();
			}
		}
		if( timer_id == 2002 ) {
			myself::LookNeighbor(500);
			myself::AddTimerEx(2001,5000);
		}
		super;
	}

	EventHandler ATTACKED(attacker,damage) {
		if( myself::InMyTerritory(attacker) == 0 ) {
			return;
		}
		if( gg::Rand(100) < 10 && myself::DistFromMe(attacker) > 100 ) {
			if( myself::Skill_GetConsumeMP(DDMagic) < myself.sm.mp && myself::Skill_GetConsumeHP(DDMagic) < myself.sm.hp && myself::Skill_InReuseDelay(DDMagic) == 0 ) {
				myself::AddUseSkillDesire(attacker,DDMagic,0,1,1000000);
			}
		}
		super;
	}

	EventHandler PARTY_ATTACKED(attacker,private,damage,f0) {
		if( myself::InMyTerritory(attacker) == 0 ) {
			return;
		}
		if( private != myself.sm && myself.sm.param1 == private.flag ) {
			if( attacker.is_pc != 0 || myself::IsInCategory(12,attacker.class_id) ) {
				if( damage == 0 ) {
					damage = 1;
				}
				myself::AddAttackDesire(attacker,1,( ( ( ( ( 1.000000 * damage ) / ( myself.sm.level + 7 ) ) * damage ) * private.weight_point ) * 10 ));
			}
		}
		if( gg::FloatToInt(( ( myself.sm.hp / myself.sm.max_hp ) * 100 )) < 50 && myself.i_ai0 == 0 ) {
			myself::BroadcastScriptEvent(10004,myself.sm.param1,1500);
			myself.i_ai0 = 1;
		}
	}

	EventHandler PARTY_DIED(private) {
		if( private == myself.sm ) {
			myself::BroadcastScriptEvent(10005,myself.sm.param1,1500);
		}
	}

	EventHandler MY_DYING(c0,c1,party0,i1,i2) {
		if( myself.i_ai1 == 1 ) {
			c0 = myself::GetLastAttacker();
			if( myself::IsNullCreature(c0) == 0 ) {
				if( c0.is_pc == 0 ) {
					c0 = c0.master;
				}
				if( myself::IsNullCreature(c0) == 0 ) {
					c0 = gg::Party_GetLeader(c0);
				}
				party0 = gg::GetPartyFromEventRoom(RoomIndex,SSQPart);
				c1 = myself::GetLeaderOfParty(party0);
				if( myself::IsNullCreature(c0) == 0 && myself::IsNullCreature(c1) == 0 ) {
					if( c0 == c1 ) {
						if( gg::HaveMemo(c0,505) ) {
							i1 = ( 3 + gg::FloatToInt(( ( 3 * 25 ) / 100 )) );
							if( myself::IsInCategory(2,c0.occupation) ) {
								if( myself::DistFromMe(c0) < 40 ) {
									i1 = ( i1 + gg::FloatToInt(( ( i1 * 30 ) / 100 )) );
								}
							} else if( myself::DistFromMe(c0) < 80 ) {
								i1 = ( i1 + gg::FloatToInt(( ( i1 * 30 ) / 100 )) );
							}
							if( myself::IsInCategory(2,c0.occupation) ) {
								if( gg::Rand(2) > 0 ) {
									i1 = ( i1 + gg::FloatToInt(( ( i1 * 7 ) / 100 )) );
								} else {
									i1 = ( i1 - gg::FloatToInt(( ( i1 * 15 ) / 100 )) );
								}
							} else if( gg::Rand(2) > 0 ) {
								i1 = ( i1 + gg::FloatToInt(( ( i1 * 15 ) / 100 )) );
							} else {
								i1 = ( i1 - gg::FloatToInt(( ( i1 * 7 ) / 100 )) );
							}
							myself::ShowSysMsgToParty2(party0,2,1381,3,5901,1,i1);
							myself::GiveItem1(c0,5901,i1);
						}
					}
				}
			}
		} else {
			c0 = myself::GetLastAttacker();
			if( myself::IsNullCreature(c0) == 0 ) {
				if( c0.is_pc == 0 ) {
					c0 = c0.master;
				}
				if( myself::IsNullCreature(c0) == 0 ) {
					c0 = gg::Party_GetLeader(c0);
				}
				party0 = gg::GetPartyFromEventRoom(RoomIndex,SSQPart);
				c1 = myself::GetLeaderOfParty(party0);
				if( myself::IsNullCreature(c0) == 0 && myself::IsNullCreature(c1) == 0 ) {
					if( c0 == c1 ) {
						if( gg::HaveMemo(c0,505) ) {
							i1 = ( 15 + gg::FloatToInt(( ( 15 * 25 ) / 100 )) );
							if( myself::IsInCategory(2,c0.occupation) ) {
								if( myself::DistFromMe(c0) < 40 ) {
									i1 = ( i1 + gg::FloatToInt(( ( i1 * 30 ) / 100 )) );
								}
							} else if( myself::DistFromMe(c0) < 80 ) {
								i1 = ( i1 + gg::FloatToInt(( ( i1 * 30 ) / 100 )) );
							}
							if( myself::IsInCategory(2,c0.occupation) ) {
								if( gg::Rand(2) > 0 ) {
									i1 = ( i1 + gg::FloatToInt(( ( i1 * 7 ) / 100 )) );
								} else {
									i1 = ( i1 - gg::FloatToInt(( ( i1 * 15 ) / 100 )) );
								}
							} else if( gg::Rand(2) > 0 ) {
								i1 = ( i1 + gg::FloatToInt(( ( i1 * 15 ) / 100 )) );
							} else {
								i1 = ( i1 - gg::FloatToInt(( ( i1 * 7 ) / 100 )) );
							}
							myself::ShowSysMsgToParty2(party0,2,1381,3,5901,1,i1);
							myself::GiveItem1(c0,5901,i1);
						}
					}
				}
			}
		}
	}

}
