public bool Run(params object[] args) { NWCreature self = Object.OBJECT_SELF; string creatureScript = self.GetLocalString("BEHAVIOUR"); if (string.IsNullOrWhiteSpace(creatureScript)) { creatureScript = self.GetLocalString("BEHAVIOR"); } if (string.IsNullOrWhiteSpace(creatureScript)) { creatureScript = self.GetLocalString("SCRIPT"); } if (string.IsNullOrWhiteSpace(creatureScript)) { return(false); } if (!App.IsKeyRegistered <IBehaviour>("AI." + creatureScript)) { return(false); } App.ResolveByInterface <IBehaviour>("AI." + creatureScript, behaviour => { if (behaviour.IgnoreNWNEvents) { self.SetLocalInt("IGNORE_NWN_EVENTS", 1); } if (behaviour.IgnoreOnBlocked) { self.SetLocalInt("IGNORE_NWN_ON_BLOCKED_EVENT", 1); } if (behaviour.IgnoreOnCombatRoundEnd) { self.SetLocalInt("IGNORE_NWN_ON_COMBAT_ROUND_END_EVENT", 1); } if (behaviour.IgnoreOnConversation) { self.SetLocalInt("IGNORE_NWN_ON_CONVERSATION_EVENT", 1); } if (behaviour.IgnoreOnDamaged) { self.SetLocalInt("IGNORE_NWN_ON_DAMAGED_EVENT", 1); } if (behaviour.IgnoreOnDeath) { self.SetLocalInt("IGNORE_NWN_ON_DEATH_EVENT", 1); } if (behaviour.IgnoreOnDisturbed) { self.SetLocalInt("IGNORE_NWN_ON_DISTURBED_EVENT", 1); } if (behaviour.IgnoreOnHeartbeat) { self.SetLocalInt("IGNORE_NWN_ON_HEARTBEAT_EVENT", 1); } if (behaviour.IgnoreOnPerception) { self.SetLocalInt("IGNORE_NWN_ON_PERCEPTION_EVENT", 1); } if (behaviour.IgnoreOnPhysicalAttacked) { self.SetLocalInt("IGNORE_NWN_ON_PHYSICAL_ATTACKED_EVENT", 1); } if (behaviour.IgnoreOnRested) { self.SetLocalInt("IGNORE_NWN_ON_RESTED_EVENT", 1); } if (behaviour.IgnoreOnSpawn) { self.SetLocalInt("IGNORE_NWN_ON_SPAWN_EVENT", 1); } if (behaviour.IgnoreOnSpellCastAt) { self.SetLocalInt("IGNORE_NWN_ON_SPELL_CAST_AT_EVENT", 1); } if (behaviour.IgnoreOnUserDefined) { self.SetLocalInt("IGNORE_NWN_ON_USER_DEFINED_EVENT", 1); } if (behaviour.Behaviour != null) { var result = behaviour.Behaviour .End() .Build(); _behaviour.RegisterBehaviour(result, self); } behaviour.OnSpawn(); }); return(true); }
public bool Run(params object[] args) { string creatureScript = Self.GetLocalString("BEHAVIOUR"); if (string.IsNullOrWhiteSpace(creatureScript)) { creatureScript = Self.GetLocalString("BEHAVIOR"); } if (string.IsNullOrWhiteSpace(creatureScript)) { creatureScript = Self.GetLocalString("SCRIPT"); } IBehaviour behaviour = null; if (!string.IsNullOrWhiteSpace(creatureScript) && App.IsKeyRegistered <IBehaviour>("AI." + creatureScript)) { behaviour = App.ResolveByInterface <IBehaviour>("AI." + creatureScript); if (behaviour.IgnoreNWNEvents) { Self.SetLocalInt("IGNORE_NWN_EVENTS", 1); } if (behaviour.IgnoreOnBlocked) { Self.SetLocalInt("IGNORE_NWN_ON_BLOCKED_EVENT", 1); } if (behaviour.IgnoreOnCombatRoundEnd) { Self.SetLocalInt("IGNORE_NWN_ON_COMBAT_ROUND_END_EVENT", 1); } if (behaviour.IgnoreOnConversation) { Self.SetLocalInt("IGNORE_NWN_ON_CONVERSATION_EVENT", 1); } if (behaviour.IgnoreOnDamaged) { Self.SetLocalInt("IGNORE_NWN_ON_DAMAGED_EVENT", 1); } if (behaviour.IgnoreOnDeath) { Self.SetLocalInt("IGNORE_NWN_ON_DEATH_EVENT", 1); } if (behaviour.IgnoreOnDisturbed) { Self.SetLocalInt("IGNORE_NWN_ON_DISTURBED_EVENT", 1); } if (behaviour.IgnoreOnHeartbeat) { Self.SetLocalInt("IGNORE_NWN_ON_HEARTBEAT_EVENT", 1); } if (behaviour.IgnoreOnPerception) { Self.SetLocalInt("IGNORE_NWN_ON_PERCEPTION_EVENT", 1); } if (behaviour.IgnoreOnPhysicalAttacked) { Self.SetLocalInt("IGNORE_NWN_ON_PHYSICAL_ATTACKED_EVENT", 1); } if (behaviour.IgnoreOnRested) { Self.SetLocalInt("IGNORE_NWN_ON_RESTED_EVENT", 1); } if (behaviour.IgnoreOnSpawn) { Self.SetLocalInt("IGNORE_NWN_ON_SPAWN_EVENT", 1); } if (behaviour.IgnoreOnSpellCastAt) { Self.SetLocalInt("IGNORE_NWN_ON_SPELL_CAST_AT_EVENT", 1); } if (behaviour.IgnoreOnUserDefined) { Self.SetLocalInt("IGNORE_NWN_ON_USER_DEFINED_EVENT", 1); } } CreatureEventType type = (CreatureEventType)args[0]; switch (type) { case CreatureEventType.OnPhysicalAttacked: behaviour?.OnPhysicalAttacked(); break; case CreatureEventType.OnBlocked: behaviour?.OnBlocked(); break; case CreatureEventType.OnConversation: behaviour?.OnConversation(); break; case CreatureEventType.OnDamaged: behaviour?.OnDamaged(); break; case CreatureEventType.OnDeath: _skill.OnCreatureDeath(Self); _loot.OnCreatureDeath(Self); if (_state.CustomObjectData.ContainsKey(Self.GlobalID)) { _state.CustomObjectData.Remove(Self.GlobalID); } behaviour?.OnDeath(); break; case CreatureEventType.OnDisturbed: behaviour?.OnDisturbed(); break; case CreatureEventType.OnHeartbeat: behaviour?.OnHeartbeat(); break; case CreatureEventType.OnPerception: behaviour?.OnPerception(); break; case CreatureEventType.OnRested: behaviour?.OnRested(); break; case CreatureEventType.OnCombatRoundEnd: behaviour?.OnCombatRoundEnd(); break; case CreatureEventType.OnSpawn: if (behaviour?.Behaviour != null) { var result = behaviour.Behaviour .End() .Build(); _behaviour.RegisterBehaviour(result, Self); } behaviour?.OnSpawn(); break; case CreatureEventType.OnSpellCastAt: behaviour?.OnSpellCastAt(); break; case CreatureEventType.OnUserDefined: behaviour?.OnUserDefined(); break; default: throw new ArgumentOutOfRangeException(); } return(true); }
public bool Run(params object[] args) { string creatureScript = Self.GetLocalString("SCRIPT"); ICreature creature = null; if (!string.IsNullOrWhiteSpace(creatureScript) && App.IsKeyRegistered <ICreature>("Creature." + creatureScript)) { creature = App.ResolveByInterface <ICreature>("Creature." + creatureScript); if (creature.IgnoreNWNEvents) { Self.SetLocalInt("IGNORE_NWN_EVENTS", 1); } if (creature.IgnoreOnBlocked) { Self.SetLocalInt("IGNORE_NWN_ON_BLOCKED_EVENT", 1); } if (creature.IgnoreOnCombatRoundEnd) { Self.SetLocalInt("IGNORE_NWN_ON_COMBAT_ROUND_END_EVENT", 1); } if (creature.IgnoreOnConversation) { Self.SetLocalInt("IGNORE_NWN_ON_CONVERSATION_EVENT", 1); } if (creature.IgnoreOnDamaged) { Self.SetLocalInt("IGNORE_NWN_ON_DAMAGED_EVENT", 1); } if (creature.IgnoreOnDeath) { Self.SetLocalInt("IGNORE_NWN_ON_DEATH_EVENT", 1); } if (creature.IgnoreOnDisturbed) { Self.SetLocalInt("IGNORE_NWN_ON_DISTURBED_EVENT", 1); } if (creature.IgnoreOnHeartbeat) { Self.SetLocalInt("IGNORE_NWN_ON_HEARTBEAT_EVENT", 1); } if (creature.IgnoreOnPerception) { Self.SetLocalInt("IGNORE_NWN_ON_PERCEPTION_EVENT", 1); } if (creature.IgnoreOnPhysicalAttacked) { Self.SetLocalInt("IGNORE_NWN_ON_PHYSICAL_ATTACKED_EVENT", 1); } if (creature.IgnoreOnRested) { Self.SetLocalInt("IGNORE_NWN_ON_RESTED_EVENT", 1); } if (creature.IgnoreOnSpawn) { Self.SetLocalInt("IGNORE_NWN_ON_SPAWN_EVENT", 1); } if (creature.IgnoreOnSpellCastAt) { Self.SetLocalInt("IGNORE_NWN_ON_SPELL_CAST_AT_EVENT", 1); } if (creature.IgnoreOnUserDefined) { Self.SetLocalInt("IGNORE_NWN_ON_USER_DEFINED_EVENT", 1); } } CreatureEventType type = (CreatureEventType)args[0]; switch (type) { case CreatureEventType.OnPhysicalAttacked: creature?.OnPhysicalAttacked(); break; case CreatureEventType.OnBlocked: creature?.OnBlocked(); break; case CreatureEventType.OnConversation: creature?.OnConversation(); break; case CreatureEventType.OnDamaged: creature?.OnDamaged(); break; case CreatureEventType.OnDeath: _skill.OnCreatureDeath(Self); _loot.OnCreatureDeath(Self); if (creature != null) { string behaviourID = Self.GetLocalString("REGISTERED_BEHAVIOUR_ID"); if (!string.IsNullOrWhiteSpace(behaviourID)) { _behaviour.UnregisterBehaviour(behaviourID); Self.DeleteLocalString("REGISTERED_BEHAVIOUR_ID"); } creature.OnDeath(); } break; case CreatureEventType.OnDisturbed: creature?.OnDisturbed(); break; case CreatureEventType.OnHeartbeat: creature?.OnHeartbeat(); break; case CreatureEventType.OnPerception: creature?.OnPerception(); break; case CreatureEventType.OnRested: creature?.OnRested(); break; case CreatureEventType.OnCombatRoundEnd: creature?.OnCombatRoundEnd(); break; case CreatureEventType.OnSpawn: if (creature != null) { if (creature.Behaviour != null) { string behaviourID = _behaviour.RegisterBehaviour(creature.Behaviour); Self.SetLocalString("REGISTERED_BEHAVIOUR_ID", behaviourID); } creature.OnSpawn(); } break; case CreatureEventType.OnSpellCastAt: creature?.OnSpellCastAt(); break; case CreatureEventType.OnUserDefined: creature?.OnUserDefined(); break; default: throw new ArgumentOutOfRangeException(); } return(true); }