public static bool IsEnmityTableEmpty(NWCreature npc) { if (!npc.IsNPC && !npc.IsDMPossessed) { throw new Exception("Only NPCs have enmity tables. Object name = " + npc.Name); } EnmityTable table = GetEnmityTable(npc); return(table.Count <= 0); }
public bool IsEnmityTableEmpty(NWCreature npc) { if (!npc.IsNPC) { throw new Exception("Only NPCs have enmity tables."); } EnmityTable table = GetEnmityTable(npc); return(table.Count <= 0); }
public static bool IsOnEnmityTable(NWCreature npc, NWCreature target) { if (!npc.IsNPC && !npc.IsDMPossessed) { throw new Exception("Only NPCs have enmity tables. Object name = " + npc.Name); } EnmityTable table = GetEnmityTable(npc); return(table.ContainsKey(target.GlobalID)); }
public bool IsOnEnmityTable(NWCreature npc, NWCreature target) { if (!npc.IsNPC) { throw new Exception("Only NPCs have enmity tables."); } EnmityTable table = GetEnmityTable(npc); return(table.ContainsKey(target.GlobalID)); }
public void RegisterPCToAllCombatTargetsForSkill(NWPlayer player, SkillType skillType, NWCreature target) { int skillID = (int)skillType; if (!player.IsPlayer) { return; } if (skillID <= 0) { return; } List <NWPlayer> members = player.PartyMembers.ToList(); int nth = 1; NWCreature creature = _.GetNearestCreature(CREATURE_TYPE_IS_ALIVE, 1, player.Object, nth, CREATURE_TYPE_PLAYER_CHAR, 0); while (creature.IsValid) { if (_.GetDistanceBetween(player.Object, creature.Object) > 20.0f) { break; } // Check NPC's enmity table EnmityTable enmityTable = _enmity.GetEnmityTable(creature); foreach (var member in members) { if (enmityTable.ContainsKey(member.GlobalID) || (target != null && target.IsValid && target == creature)) { RegisterPCToNPCForSkill(player, creature, skillID); break; } } nth++; creature = _.GetNearestCreature(CREATURE_TYPE_IS_ALIVE, 1, player.Object, nth, CREATURE_TYPE_PLAYER_CHAR, 0); } }
public void OnImpact(NWPlayer oPC, NWObject oTarget) { NWCreature npc = NWCreature.Wrap(oTarget.Object); Effect vfx = _.EffectVisualEffect(VFX_IMP_CHARM); _.ApplyEffectToObject(DURATION_TYPE_INSTANT, vfx, oTarget.Object); oPC.AssignCommand(() => { _.ActionPlayAnimation(ANIMATION_FIREFORGET_TAUNT, 1f, 1f); }); _enmity.AdjustEnmity(npc, oPC, 120); // todo debugging EnmityTable table = _enmity.GetEnmityTable(npc); foreach (var x in table.Values) { Console.WriteLine(npc.Name + ", " + x.TargetObject.Name + ": Volatile = " + x.VolatileAmount + ", Cumulative: " + x.CumulativeAmount); } // todo end debugging }
public BehaviourTreeBuilder Build(BehaviourTreeBuilder builder, params object[] args) { NWCreature self = (NWCreature)args[0]; return(builder.Do("WarpToTargetIfStuck", t => { if (_enmity.IsEnmityTableEmpty(self) || _.GetMovementRate(self.Object) == 1) // 1 = Immobile { if (self.Data.ContainsKey("WarpToTargetIfStuck_Position")) { self.Data.Remove("WarpToTargetIfStuck_Position"); } if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace")) { self.Data.Remove("WarpToTargetIfStuck_CyclesStuckInPlace"); } return BehaviourTreeStatus.Failure; } Vector previousPosition = new Vector(); if (self.Data.ContainsKey("WarpToTargetIfStuck_Position")) { previousPosition = (Vector)self.Data["WarpToTargetIfStuck_Position"]; } Vector currentPosition = self.Position; if (previousPosition.m_X == currentPosition.m_X && previousPosition.m_Y == currentPosition.m_Y && previousPosition.m_Z == currentPosition.m_Z) { var cyclesStuck = 0; if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace")) { cyclesStuck = (int)self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"]; } cyclesStuck++; if (cyclesStuck >= 12) // Stuck for 12 seconds - warp to the target if still in the area. { EnmityTable table = _enmity.GetEnmityTable(self); var topTarget = table.Values.OrderByDescending(o => o.TotalAmount).SingleOrDefault(); if (topTarget != null && topTarget.TargetObject.IsValid) { var location = topTarget.TargetObject.Location; _.AssignCommand(self.Object, () => _.JumpToLocation(location)); } cyclesStuck = 0; } self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = cyclesStuck; } else { self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = 0; } self.Data["WarpToTargetIfStuck_Position"] = currentPosition; return BehaviourTreeStatus.Running; })); }
public bool Run(object[] args) { NWCreature self = (NWCreature)args[0]; if (_enmity.IsEnmityTableEmpty(self) || _.GetMovementRate(self.Object) == 1 || // 1 = Immobile self.HasAnyEffect(EFFECT_TYPE_DAZED) || // Dazed self.RightHand.CustomItemType == CustomItemType.BlasterRifle || self.RightHand.CustomItemType == CustomItemType.BlasterPistol) { if (self.Data.ContainsKey("WarpToTargetIfStuck_Position")) { self.Data.Remove("WarpToTargetIfStuck_Position"); } if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace")) { self.Data.Remove("WarpToTargetIfStuck_CyclesStuckInPlace"); } return(false); } Vector previousPosition = new Vector(); if (self.Data.ContainsKey("WarpToTargetIfStuck_Position")) { previousPosition = (Vector)self.Data["WarpToTargetIfStuck_Position"]; } Vector currentPosition = self.Position; if (previousPosition.m_X == currentPosition.m_X && previousPosition.m_Y == currentPosition.m_Y && previousPosition.m_Z == currentPosition.m_Z) { var cyclesStuck = 0; if (self.Data.ContainsKey("WarpToTargetIfStuck_CyclesStuckInPlace")) { cyclesStuck = (int)self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"]; } cyclesStuck++; if (cyclesStuck >= 12) // Stuck for 12 seconds - warp to the target if still in the area. { EnmityTable table = _enmity.GetEnmityTable(self); var topTarget = table.Values.OrderByDescending(o => o.TotalAmount).FirstOrDefault(); if (topTarget != null && topTarget.TargetObject.IsValid) { var location = topTarget.TargetObject.Location; _.AssignCommand(self.Object, () => _.JumpToLocation(location)); } cyclesStuck = 0; } self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = cyclesStuck; } else { self.Data["WarpToTargetIfStuck_CyclesStuckInPlace"] = 0; } self.Data["WarpToTargetIfStuck_Position"] = currentPosition; return(true); }