Beispiel #1
0
 public BehaviourStatus DrinkPotion(Creature arg)
 {
     if (HasLowHealth(arg))
     {
         // 695 is healing pot model - bit of hack
         // This needs to be timed if we dont have a proper inventory to work with.
         var items = CreatureService.GetCreatureItems((arg as Creature).Entry).Where(x => x.ModelId == 695);
         // Low health -- potion of healing
         if (items.Count() > 0)
         {
             // 7872 - Potion of Healing ability
             SpeakYourMind($" using Potion of Healing");
             return(arg.AbtInterface.StartCast(arg, 7872, 1)
                 ? BehaviourStatus.Succeeded
                 : BehaviourStatus.Failed);
         }
         else
         {
             return(BehaviourStatus.Failed);
         }
     }
     else
     {
         return(BehaviourStatus.Failed);
     }
 }
Beispiel #2
0
        public virtual void SpawnAdds(object crea)
        {
            var Params = (List <object>)crea;

            int    Entry = (int)Params[0];
            int    X     = (int)Params[1];
            int    Y     = (int)Params[2];
            int    Z     = (int)Params[3];
            ushort O     = (ushort)Params[4];

            Creature_proto Proto = CreatureService.GetCreatureProto((uint)Entry);

            Creature_spawn Spawn = new Creature_spawn();

            Spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
            Spawn.BuildFromProto(Proto);
            Spawn.WorldO = (int)O;
            Spawn.WorldX = X;
            Spawn.WorldY = Y;
            Spawn.WorldZ = Z;
            Spawn.ZoneId = (ushort)Obj.ZoneId;
            Spawn.Level  = 3;
            Creature c = Obj.Region.CreateCreature(Spawn);

            c.EvtInterface.AddEventNotify(EventName.OnDie, RemoveAdds); // We are removing spawns from server when adds die
            addList.Add(c);                                             // Adding adds to the list for easy removal
        }
        public override void SpawnAdds(object crea)
        {
            var Params = (List <object>)crea;

            int        Entry = (int)Params[0];
            int        X     = (int)Params[1];
            int        Y     = (int)Params[2];
            int        Z     = (int)Params[3];
            ushort     O     = (ushort)Params[4];
            GameObject go    = Obj as GameObject;

            if (go != null && !go.IsDead)
            {
                Creature_proto Proto = CreatureService.GetCreatureProto((uint)Entry);

                Creature_spawn Spawn = new Creature_spawn();
                Spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
                Spawn.BuildFromProto(Proto);
                Spawn.WorldO = (int)O;
                Spawn.WorldX = X;
                Spawn.WorldY = Y;
                Spawn.WorldZ = Z;
                Spawn.ZoneId = (ushort)Obj.ZoneId;
                //Spawn.Level = 40;
                Creature c = Obj.Region.CreateCreature(Spawn);
                c.EvtInterface.AddEventNotify(EventName.OnDie, RemoveAdds); // We are removing spawns from server when adds die
                addList.Add(c);                                             // Adding adds to the list for easy removal

                go.EvtInterface.AddEvent(SpawnAdds, 15000, 1, Params);
            }
            else
            {
                go.EvtInterface.RemoveEvent(SpawnAdds);
            }
        }
Beispiel #4
0
        public static SiegeType?GetSiegeType(uint primaryValue)
        {
            var siegeProto = CreatureService.GetCreatureProto(primaryValue);

            if (siegeProto == null)
            {
                return(null);
            }

            SiegeType siegeType;


            switch ((GameData.CreatureSubTypes)siegeProto.CreatureSubType)
            {
            case GameData.CreatureSubTypes.SIEGE_GTAOE:
                siegeType = SiegeType.GTAOE;
                break;

            case GameData.CreatureSubTypes.SIEGE_SINGLE_TARGET:
                siegeType = SiegeType.SNIPER;
                break;

            case GameData.CreatureSubTypes.SIEGE_RAM:
                siegeType = SiegeType.RAM;
                break;

            default:
                siegeType = SiegeType.RAM;
                break;
            }

            return(siegeType);
        }
Beispiel #5
0
        public override void OnDie(Object Obj)
        {
            // Spawn the bad npc
            Creature_proto Proto = CreatureService.GetCreatureProto((uint)135);

            if (Proto == null)
            {
                return;
            }

            Obj.UpdateWorldPosition();

            Creature_spawn Spawn = new Creature_spawn();

            Spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
            Spawn.BuildFromProto(Proto);
            Spawn.WorldO  = Obj.Heading;
            Spawn.WorldY  = Obj.WorldPosition.Y;
            Spawn.WorldZ  = Obj.WorldPosition.Z;
            Spawn.WorldX  = Obj.WorldPosition.X;
            Spawn.ZoneId  = Obj.Zone.ZoneId;
            Spawn.Faction = 72;
            Spawn.Emote   = 53;

            Creature c = Obj.Region.CreateCreature(Spawn);

            //  The villager will be disposed in 20 secs
            c.EvtInterface.AddEvent(c.Destroy, 20000, 1);
        }
Beispiel #6
0
        public void SpawnGuard(int team)
        {
            if (Creature != null)
            {
                Creature.Destroy();
            }
            this.team = team;

            Creature_proto Proto = CreatureService.GetCreatureProto(team == 1 ? OrderId : DestroId);

            if (Proto == null)
            {
                Log.Error("FlagGuard", "No FlagGuard Proto");
                return;
            }

            Creature_spawn Spawn = new Creature_spawn();

            Spawn.BuildFromProto(Proto);
            Spawn.WorldO         = o;
            Spawn.WorldY         = y;
            Spawn.WorldZ         = z;
            Spawn.WorldX         = x;
            Spawn.ZoneId         = ZoneId;
            Spawn.RespawnMinutes = 3;

            Creature = new GuardCreature(Spawn, this);
            Region.AddObject(Creature, Spawn.ZoneId);
        }
        /// <summary>
        /// Add Equipement to target <Model,Slot,Save>
        /// </summary>
        /// <param name="plr">Player that initiated the command</param>
        /// <param name="values">List of command arguments (after command name)</param>
        /// <returns>True if command was correctly handled, false if operation was canceled</returns>
        public static bool EquipAdd(Player plr, ref List <string> values)
        {
            int model = GetInt(ref values);
            int slot  = GetInt(ref values);
            int save  = GetInt(ref values);

            Creature obj = GetObjectTarget(plr) as Creature;

            if (obj == null)
            {
                return(false);
            }

            Creature_item item = new Creature_item();

            item.SlotId   = (ushort)slot;
            item.ModelId  = (ushort)model;
            item.Entry    = obj.Entry;
            item.EffectId = 0;
            obj.ItmInterface.AddCreatureItem(item);
            plr.SendClientMessage("Item Added :" + (ushort)slot);
            if (save > 0)
            {
                CreatureService.AddCreatureItem(item);
            }

            return(true);
        }
Beispiel #8
0
        public void SwitchBodiesWith_GivenCorrectIdDifferentFromPreviousAllysId_ShouldPreserveOpponentsHPLeftPercentageRoundedUp()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            const int oldAllysId = 9;

            creatureService.MakeGivenCreatureFriendly(oldAllysId);
            const int newAllysId   = 2;
            byte      oldOppsMaxHP = creatureService.GetCreatureMaxHPById(newAllysId);

            creatureService.RegisterHit((byte)(oldOppsMaxHP / 3), newAllysId);
            byte oldOppsHP = creatureService.GetCreatureCurrentHPById(newAllysId);

            //Act
            creatureService.SwitchBodiesWith(newAllysId);
            //Assert
            byte newOppsHP    = creatureService.GetCreatureCurrentHPById(oldAllysId);
            byte newOppsMaxHP = creatureService.GetCreatureMaxHPById(oldAllysId);

            // oldHP/oldMax + epsilon = newHP/newMax, 0 <= epsilon < 1/newMax (round up, but by no more than 1 point)
            // multiply both sides by oldMax*newMax to get:
            // epsilon*oldMax*newMax = newHP*oldMax - oldHP*newMax
            // so that thing on the right is between 0 (inclusive) and oldMax (exclusive)
            // Assert.InRange(5, 5, 7) and Assert.InRange(7, 5, 7) both pass, so that's an inclusive range.
            Assert.InRange(newOppsHP * oldOppsMaxHP - oldOppsHP * newOppsMaxHP, 0, oldOppsMaxHP - 1);
        }
        /// <summary>
        /// Remove All Equipements to target <Save>
        /// </summary>
        /// <param name="plr">Player that initiated the command</param>
        /// <param name="values">List of command arguments (after command name)</param>
        /// <returns>True if command was correctly handled, false if operation was canceled</returns>
        public static bool EquipClear(Player plr, ref List <string> values)
        {
            int save = GetInt(ref values);

            Creature obj = GetObjectTarget(plr) as Creature;

            if (obj == null)
            {
                return(false);
            }

            for (int i = 0; i < ItemsInterface.MAX_EQUIPMENT_SLOT; ++i)
            {
                if (obj.ItmInterface.Items[i] != null)
                {
                    if (obj.ItmInterface.RemoveCreatureItem((ushort)i) != null)
                    {
                        plr.SendClientMessage("Item Removed :" + (ushort)i);
                        if (save > 0)
                        {
                            CreatureService.RemoveCreatureItem(obj.Entry, (ushort)i);
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #10
0
        public override void SpawnAdds(object crea)
        {
            var Params = (List <object>)crea;

            int        Entry = (int)Params[0];
            int        X     = (int)Params[1];
            int        Y     = (int)Params[2];
            int        Z     = (int)Params[3];
            ushort     O     = (ushort)Params[4];
            GameObject go    = Obj as GameObject;

            if (go != null && !go.IsDead)
            {
                Creature_proto Proto = CreatureService.GetCreatureProto((uint)Entry);

                Creature_spawn Spawn = new Creature_spawn();
                Spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
                Spawn.BuildFromProto(Proto);
                Spawn.WorldO = (int)O;
                Spawn.WorldX = X;
                Spawn.WorldY = Y;
                Spawn.WorldZ = Z;
                Spawn.ZoneId = (ushort)Obj.ZoneId;

                int count = 0;

                foreach (Player player in Obj.PlayersInRange)
                {
                    if (player.Realm == GameData.Realms.REALMS_REALM_ORDER)
                    {
                        count++;
                    }
                    else
                    {
                        count--;
                    }
                }

                if (count > 0)
                {
                    Spawn.Faction = 131;
                }
                else
                {
                    Spawn.Faction = 67;
                }

                //Spawn.Level = 40;
                Creature c = Obj.Region.CreateCreature(Spawn);
                c.EvtInterface.AddEventNotify(EventName.OnDie, RemoveAdds); // We are removing spawns from server when adds die
                addList.Add(c);                                             // Adding adds to the list for easy removal

                go.EvtInterface.AddEvent(SpawnAdds, 20 * 1000, 1, Params);
            }
            else
            {
                go.EvtInterface.RemoveEvent(SpawnAdds);
            }
        }
        public void ThrowExceptionWhenCreatureServiceIsNull()
        {
            // Arrange
            CreatureService creatureServiceMock = null;
            var             orderServiceMock    = new Mock <IOrderService>();

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => new AquaWorld.Web.Areas.Admin.AdminController(creatureServiceMock, orderServiceMock.Object));
        }
        public void SpawnGuard(Realms realm)
        {
            if (Creature != null)
            {
                Creature.Destroy();
                Creature = null;

                /*if (Info.KeepLord)
                 *  Log.Info(Keep.Info.Name, (Keep.Realm == Realms.REALMS_REALM_ORDER ? "Order" : "Destruction") + " keep lord disposed.");*/
            }

            if (realm != Realms.REALMS_REALM_NEUTRAL)
            {
                Creature_proto proto = CreatureService.GetCreatureProto(realm == Realms.REALMS_REALM_ORDER ? Info.OrderId : Info.DestroId);
                if (proto == null)
                {
                    Log.Error("KeepNPC", "No FlagGuard Proto");
                    return;
                }

                Creature_spawn spawn = new Creature_spawn();
                spawn.BuildFromProto(proto);
                spawn.WorldO = Info.O;

                /*
                 * if (proto.CreatureType == 32 && Info.Y < 70000)
                 * {
                 *  WorldMgr.Database.DeleteObject(Info);
                 *  Keep_Creature newInfo = new Keep_Creature
                 *  {
                 *      KeepId = Info.KeepId,
                 *      ZoneId = Info.ZoneId,
                 *      OrderId = Info.OrderId,
                 *      DestroId = Info.DestroId,
                 *      X = Info.X,
                 *      Y = ZoneMgr.CalculWorldPosition(WorldMgr.GetZone_Info(Info.ZoneId), 0, (ushort) Info.Y, 0).Y,
                 *      Z = Info.Z,
                 *      O = Info.O
                 *  };
                 *  WorldMgr.Database.AddObject(newInfo);
                 *
                 *  Info = newInfo;
                 * }*/
                spawn.WorldY = Info.Y;
                spawn.WorldZ = Info.Z;
                spawn.WorldX = Info.X;
                spawn.ZoneId = Info.ZoneId;

                Creature = new KeepCreature(spawn, this, Keep);

                /*if (Info.KeepLord)
                 *  Log.Info(Keep.Info.Name, (Keep.Realm == Realms.REALMS_REALM_ORDER ? "Order" : "Destruction") + " keep lord spawned.");*/
                Region.AddObject(Creature, spawn.ZoneId);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Spawn an npc
        /// </summary>
        /// <param name="plr">Player that initiated the command</param>
        /// <param name="values">List of command arguments (after command name)</param>
        /// <returns>True if command was correctly handled, false if operation was canceled</returns>
        public static bool NpcSpawn(Player plr, ref List <string> values)
        {
            int entry = GetInt(ref values);

            Creature_proto proto = CreatureService.GetCreatureProto((uint)entry);

            if (proto == null)
            {
                proto = WorldMgr.Database.SelectObject <Creature_proto>("Entry=" + entry);

                if (proto != null)
                {
                    plr.SendClientMessage("NPC SPAWN: Npc Entry is valid but npc stats are empty. No sniff data about this npc");
                }
                else
                {
                    plr.SendClientMessage("NPC SPAWN:  Invalid npc entry(" + entry + ")");
                }

                return(false);
            }

            plr.UpdateWorldPosition();

            Creature_spawn spawn = new Creature_spawn();

            spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
            spawn.BuildFromProto(proto);
            spawn.WorldO  = plr._Value.WorldO;
            spawn.WorldY  = plr._Value.WorldY;
            spawn.WorldZ  = plr._Value.WorldZ;
            spawn.WorldX  = plr._Value.WorldX;
            spawn.ZoneId  = plr.Zone.ZoneId;
            spawn.Enabled = 1;

            WorldMgr.Database.AddObject(spawn);

            var c = plr.Region.CreateCreature(spawn);

            c.AiInterface.SetBrain(new PassiveBrain(c));


            GMCommandLog log = new GMCommandLog();

            log.PlayerName = plr.Name;
            log.AccountId  = (uint)plr.Client._Account.AccountId;
            log.Command    = "SPAWN CREATURE " + spawn.Entry + " " + spawn.Guid + " AT " + spawn.ZoneId + " " + plr._Value.WorldX + " " + plr._Value.WorldY;
            log.Date       = DateTime.Now;
            CharMgr.Database.AddObject(log);

            return(true);
        }
Beispiel #14
0
        public void GenerateNewCrts_ShouldGenerateCreaturesAtFullHealth()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            //Act
            creatureService.GenerateNewCrts();
            //Assert
            for (int id = 0; id < DisplaySettings.NumberOfOpps; id++)
            {
                Assert.Equal(creatureService.GetCreatureMaxHPById(id), creatureService.GetCreatureCurrentHPById(id));
            }
        }
Beispiel #15
0
        public void GenerateNewCrts_ShouldMakeEveryoneHostile()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            //Act
            creatureService.GenerateNewCrts();
            //Assert
            for (int id = 0; id < DisplaySettings.NumberOfOpps; id++)
            {
                Assert.False(creatureService.IsCreatureFriendly(id));
            }
        }
Beispiel #16
0
        /// <summary>
        /// Adds speech to the targeted NPC, by spawn (string text)
        /// </summary>
        /// <param name="plr">Player that initiated the command</param>
        /// <param name="values">List of command arguments (after command name)</param>
        /// <returns>True if command was correctly handled, false if operation was canceled</returns>
        public static bool NpcQuote(Player plr, ref List <string> values)
        {
            Creature npc = plr.CbtInterface.GetCurrentTarget() as Creature;

            if (npc == null || npc.Spawn.Entry == 0 || npc is Pet || npc is PQuestCreature || npc is KeepCreature)
            {
                plr.SendClientMessage("NPC QUOTE: This command may only be used on a static creature.");
                return(true);
            }

            CreatureService.AddCreatureText(npc.Spawn.Entry, GetTotalString(ref values));
            return(true);
        }
Beispiel #17
0
        public override void OnDie(Object Obj)
        {
            // Respawn the orginal npc
            Creature_proto Proto = CreatureService.GetCreatureProto((uint)32);

            if (Proto == null)
            {
                return;
            }

            Obj.UpdateWorldPosition();

            Creature_spawn Spawn = new Creature_spawn();

            Spawn.Guid   = (uint)CreatureService.GenerateCreatureSpawnGUID();
            Proto.Model1 = Obj.GetCreature().Spawn.Proto.Model1;
            Spawn.BuildFromProto(Proto);
            Spawn.WorldO = O;
            Spawn.WorldY = Y;
            Spawn.WorldZ = Z;
            Spawn.WorldX = X;
            Spawn.ZoneId = Obj.Zone.ZoneId;
            //Spawn.Faction = 65;

            Creature c = Obj.Region.CreateCreature(Spawn);

            //  Set the new NPC to dead, there should be a method to do this perhaps.
            c.Health = 0;

            c.States.Add(3); // Death State

            PacketOut Out = new PacketOut((byte)Opcodes.F_OBJECT_DEATH);

            Out.WriteUInt16(c.Oid);
            Out.WriteByte(1);
            Out.WriteByte(0);
            Out.WriteUInt16(0);
            Out.Fill(0, 6);
            c.DispatchPacket(Out, true);

            //  Make it respawn
            //var prms = new List<object>() { c };

            //c.EvtInterface.AddEvent(TeleportToSpawnPlace, 29000 + c.Level * 1000, 1, prms);
            c.EvtInterface.AddEvent(c.RezUnit, 30000 + c.Level * 1000, 1); // 30 seconde Rez

            // Remove the old npc
            Obj.Destroy();

            return;
        }
Beispiel #18
0
        public void RegisterHit_GivenOverkillDamage_ShouldDecreaseTargetsHPToZero()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            const byte damage   = byte.MaxValue;
            const int  targetId = 9;

            //Act
            creatureService.RegisterHit(damage, targetId);
            //Assert
            Assert.Equal(0, creatureService.GetCreatureCurrentHPById(targetId));
        }
Beispiel #19
0
        public void SpawnBaddies()
        {
            Creature_proto Proto = CreatureService.GetCreatureProto((uint)43);

            if (Proto == null)
            {
                return;
            }

            if (Quote == 0)
            {
                Obj.Say("Hold your ground, hold your ground! ", SystemData.ChatLogFilters.CHATLOGFILTERS_MONSTER_SAY);
            }
            else if (Quote == 1)
            {
                Obj.Say("I see in your eyes the same fear that would take the heart of me.", SystemData.ChatLogFilters.CHATLOGFILTERS_MONSTER_SAY);
            }
            else if (Quote == 2)
            {
                Obj.Say("A day may come when the courage of men fails, when we forsake our friends and break all bonds of fellowship, but it is not this day.", SystemData.ChatLogFilters.CHATLOGFILTERS_MONSTER_SAY);
            }
            else if (Quote == 3)
            {
                Obj.Say("An hour of wolves and shattered shields, when the age of men comes crashing down!", SystemData.ChatLogFilters.CHATLOGFILTERS_MONSTER_SAY);
            }
            else if (Quote == 4)
            {
                Obj.Say("But it is not this day! This day we fight!", SystemData.ChatLogFilters.CHATLOGFILTERS_MONSTER_SAY);
            }

            Quote++;

            Random rand = new Random();

            for (int i = 0; i < 3; i++)
            {
                Creature_spawn Spawn = new Creature_spawn();
                Spawn.Guid = (uint)CreatureService.GenerateCreatureSpawnGUID();
                Spawn.BuildFromProto(Proto);
                Spawn.WorldO = Obj.Heading;
                Spawn.WorldX = (int)(Obj.WorldPosition.X + 150 - 300 * rand.NextDouble());
                Spawn.WorldY = (int)(Obj.WorldPosition.Y + 150 - 300 * rand.NextDouble());
                Spawn.WorldZ = Obj.WorldPosition.Z;
                Spawn.ZoneId = Obj.Zone.ZoneId;
                Creature c = Obj.Region.CreateCreature(Spawn);
                //c.GetCreature().MvtInterface.WalkTo(Obj.WorldPosition.X, Obj.WorldPosition.Y, Obj.WorldPosition.Z, MovementInterface.CREATURE_SPEED);
                c.EvtInterface.AddEvent(c.Destroy, 20000, 1);
            }
        }
Beispiel #20
0
        public void RegisterHit_GivenLowDamage_ShouldDecreaseTargetsCurrentHPByGivenDamage()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            const byte damage   = 2;
            const int  targetId = 7;
            byte       expected = (byte)(creatureService.GetCreatureCurrentHPById(targetId) - damage);

            //Act
            creatureService.RegisterHit(damage, targetId);
            //Assert
            Assert.Equal(expected, creatureService.GetCreatureCurrentHPById(targetId));
        }
Beispiel #21
0
        public void MakeGivenCreatureFriendly_GivenCorrectId_ShouldChangeGivenCreatureToAlly()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            const int id = 5;

            // check assumption:
            Assert.False(creatureService.IsCreatureFriendly(id));
            //Act
            creatureService.MakeGivenCreatureFriendly(id);
            //Assert
            Assert.True(creatureService.IsCreatureFriendly(id));
        }
Beispiel #22
0
        public virtual void SpawnAdds(List <List <object> > listOfSpawnAdds)
        {
            List <object> Params = GetRandomSpawnParams(listOfSpawnAdds);

            List <uint> Entries = (List <uint>)Params[0];
            int         X       = (int)Params[1];
            int         Y       = (int)Params[2];
            int         Z       = (int)Params[3];
            ushort      O       = Convert.ToUInt16(Params[4]);

            foreach (var entry in Entries)
            {
                Creature_proto Proto = CreatureService.GetCreatureProto(entry);

                Creature_spawn Spawn = new Creature_spawn
                {
                    Guid = (uint)CreatureService.GenerateCreatureSpawnGUID()
                };
                Spawn.BuildFromProto(Proto);
                Spawn.WorldO = O;
                Spawn.WorldX = X + ShuffleWorldCoordinateOffset(20, 100);
                Spawn.WorldY = Y + ShuffleWorldCoordinateOffset(20, 100);
                Spawn.WorldZ = Z;
                Spawn.ZoneId = (ushort)ZoneId;

                Creature c = Region.CreateCreature(Spawn);
                //c.SetZone(Region.GetZoneMgr((ushort)ZoneId));
                c.EvtInterface.AddEventNotify(EventName.OnDie, RemoveAdds); // We are removing spawns from server when adds die
                c.PlayersInRange = PlayersInRange;

                // brain distribution
                switch (entry)
                {
                //case 6861: // healerbrain for shamans
                //    c.AiInterface.SetBrain(new SimpleLVHealerBrain(c));
                //    //GoToMommy(c);
                //    SetRandomTarget(c);
                //    break;

                default:
                    SetRandomTarget(c);
                    break;
                }

                AddList.Add(c); // Adding adds to the list for easy removal
            }
        }
Beispiel #23
0
        public void SwitchBodiesWith_GivenCorrectIdDifferentFromPreviousAllysId_ShouldSwitchAllegiancesOfOldAllyAndGivenOpponent()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            const int oldAllysId = 1;

            creatureService.MakeGivenCreatureFriendly(oldAllysId);
            const int newAllysId = 0;

            //Act
            creatureService.SwitchBodiesWith(newAllysId);
            //Assert
            Assert.True(creatureService.IsCreatureFriendly(newAllysId));
            Assert.False(creatureService.IsCreatureFriendly(oldAllysId));
        }
Beispiel #24
0
        private void Spawn(BossSpawn entry)
        {
            ushort facing = 2093;

            var X = Owner.WorldPosition.X;
            var Y = Owner.WorldPosition.Y;
            var Z = Owner.WorldPosition.Z;


            var spawn = new Creature_spawn {
                Guid = (uint)CreatureService.GenerateCreatureSpawnGUID()
            };
            var proto = CreatureService.GetCreatureProto(entry.ProtoId);

            if (proto == null)
            {
                return;
            }
            spawn.BuildFromProto(proto);

            spawn.WorldO = facing;
            spawn.WorldX = X + StaticRandom.Instance.Next(500);
            spawn.WorldY = Y + StaticRandom.Instance.Next(500);
            spawn.WorldZ = Z;
            spawn.ZoneId = (ushort)Owner.ZoneId;


            var creature = Owner.Region.CreateCreature(spawn);

            creature.EvtInterface.AddEventNotify(EventName.OnDie, RemoveNPC);
            entry.Creature = creature;
            (Owner as Boss).SpawnDictionary.Add(entry);

            if (entry.Type == BrainType.AggressiveBrain)
            {
                creature.AiInterface.SetBrain(new AggressiveBrain(creature));
            }
            if (entry.Type == BrainType.HealerBrain)
            {
                creature.AiInterface.SetBrain(new HealerBrain(creature));
            }
            if (entry.Type == BrainType.PassiveBrain)
            {
                creature.AiInterface.SetBrain(new PassiveBrain(creature));
            }
        }
Beispiel #25
0
        public void SpawnGuard(Realms realm)
        {
            if (Creature != null)
            {
                Creature.Destroy();
                Creature = null;
            }

            if (realm != Realms.REALMS_REALM_NEUTRAL)
            {
                if (Info.DestroId == 0 && realm == Realms.REALMS_REALM_DESTRUCTION)
                {
                    _logger.Trace($"Creature Id = 0, no spawning");
                }
                else
                {
                    Creature_proto proto = CreatureService.GetCreatureProto(realm == Realms.REALMS_REALM_ORDER ? Info.OrderId : Info.DestroId);

                    if (proto == null)
                    {
                        Log.Error("KeepNPC", "No FlagGuard Proto");
                        return;
                    }
                    _logger.Trace($"Spawning Guard {proto.Name} ({proto.Entry})");

                    Creature_spawn spawn = new Creature_spawn();
                    spawn.BuildFromProto(proto);
                    spawn.WorldO = Info.O;
                    spawn.WorldX = Info.X;
                    spawn.WorldY = Info.Y;
                    spawn.WorldZ = Info.Z;
                    spawn.ZoneId = Info.ZoneId;

                    Creature = new KeepCreature(spawn, this, Keep);
                    Creature.WaypointGUID = Convert.ToUInt32(Info.WaypointGUID);
                    if (Info.WaypointGUID > 0)
                    {
                        Creature.AiInterface.Waypoints = WaypointService.GetKeepNpcWaypoints(Info.WaypointGUID);
                    }


                    Region.AddObject(Creature, spawn.ZoneId);
                }
            }
        }
Beispiel #26
0
        public void UpdateFlagOwningRealm()
        {
            Creature_proto Proto = CreatureService.GetCreatureProto(team == 1 ? OrderId : DestroId);

            if (Proto == null)
            {
                Log.Error("FlagGuard", "No FlagGuard Proto");
                return;
            }

            Creature.Spawn = new Creature_spawn();
            Creature.Spawn.BuildFromProto(Proto);
            Creature.Spawn.WorldO         = o;
            Creature.Spawn.WorldY         = y;
            Creature.Spawn.WorldZ         = z;
            Creature.Spawn.WorldX         = x;
            Creature.Spawn.ZoneId         = ZoneId;
            Creature.Spawn.RespawnMinutes = 3;
        }
        /// <summary>
        /// Reload creatures in your region
        /// </summary>
        /// <param name="plr">Player that initiated the command</param>
        /// <param name="values">List of command arguments (after command name)</param>
        /// <returns>True if command was correctly handled, false if operation was canceled</returns>
        public static bool ReloadCreatures(Player plr, ref List <string> values)
        {
            CreatureService.LoadCreatureItems();
            plr.SendClientMessage("RELOADCREATURES: NPC Items Loaded : " + CreatureService._CreatureItems.Count);

            CreatureService.LoadCreatureProto();
            plr.SendClientMessage("RELOADCREATURES: NPCs Loaded : " + CreatureService.CreatureProtos.Count);

            CreatureService.LoadCreatureStats();
            plr.SendClientMessage("RELOADCREATURES: Stats Loaded : " + CreatureService._CreatureStats.Count);

            BattleFrontService.LoadKeepCreatures();
            plr.SendClientMessage("RELOADCREATURES: Keep Creatures Loaded : " + BattleFrontService._KeepCreatures.Count);

            CreatureService.LoadBossSpawns();
            plr.SendClientMessage("RELOADCREATURES: Bosses Loaded : " + CreatureService.BossSpawns.Count);

            List <Object> allCells = new List <Object>();

            allCells.AddRange(plr._Cell.Objects);
            foreach (Object obj in allCells)
            {
                if (obj.IsCreature())
                {
                    Creature crea = obj.GetCreature();
                    try
                    {
                        var proto = CreatureService.CreatureProtos[crea.Entry];
                        crea.Spawn.Proto = proto;
                    }
                    catch
                    {
                        plr.SendClientMessage("RELOADCREATURES: NPC with Entry " + crea.Entry + " not found in CreatureProtos, removing NPC");
                        crea.Spawn.Proto = null;
                    }
                    crea.Region.CreateCreature(crea.Spawn);
                    crea.Dispose();
                }
            }
            plr.SendClientMessage("RELOADCREATURES: NPC spawn's Loaded : " + CreatureService.CreatureSpawns.Count);
            return(true);
        }
Beispiel #28
0
        public void MakeGivenCreatureFriendly_GivenCorrectId_ShouldNotChangeCreatureStats()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            int id        = 5;
            var oldMaxHP  = creatureService.GetCreatureMaxHPById(id);
            var oldCurrHP = creatureService.GetCreatureCurrentHPById(id);
            var oldSpeed  = creatureService.GetCreatureSpeedById(id);
            var oldAttack = creatureService.GetCreatureAttackById(id);

            //Act
            creatureService.MakeGivenCreatureFriendly(id);
            //Assert
            Assert.Equal(oldAttack, creatureService.GetCreatureAttackById(id));
            Assert.Equal(oldSpeed, creatureService.GetCreatureSpeedById(id));
            Assert.Equal(oldCurrHP, creatureService.GetCreatureCurrentHPById(id));
            Assert.Equal(oldMaxHP, creatureService.GetCreatureMaxHPById(id));
        }
Beispiel #29
0
        public void MakeGivenCreatureFriendly_GivenNegativeId_ShouldThrowArgumentException()
        {
            //Arrange
            ICreatureService creatureService = new CreatureService();

            creatureService.GenerateNewCrts();
            bool caught = false;

            //Act
            try
            {
                creatureService.MakeGivenCreatureFriendly(-1);
            }
            catch (ArgumentException)
            {
                caught = true;
            }
            //Assert
            Assert.True(caught);
        }
Beispiel #30
0
        public static Siege SpawnSiegeWeapon(Player plr, ushort zoneId, uint entry, bool defender)
        {
            Creature_proto proto = CreatureService.GetCreatureProto(entry);

            Creature_spawn spawn = null;

            spawn = new Creature_spawn
            {
                Guid   = (uint)CreatureService.GenerateCreatureSpawnGUID(),
                WorldO = plr.Heading,
                WorldY = plr.WorldPosition.Y,
                WorldZ = plr.Z,
                WorldX = plr.WorldPosition.X,
                ZoneId = zoneId,
                Level  = 40
            };

            spawn.BuildFromProto(proto);

            return(new Siege(spawn, plr, GetSiegeType(entry).Value));
        }