Exemplo n.º 1
0
        internal void SetNpc(int id)
        {
            if (npcs == null)
            {
                npcs = new SortedList <int, L2Citizen>();
            }

            NpcTemplate t   = NpcTable.Instance.getNpcTemplate(id);
            L2Citizen   npc = null;

            switch (t.NpcId)
            {
            case 35461:
                npc = new L2HideoutManager(this);
                break;

            case 35462:
                npc = new L2Doormen(this);
                break;
            }

            npc.setTemplate(t);

            StructureSpawn ss = StructureTable.Instance.GetSpawn(id);

            npc.X       = ss.x;
            npc.Y       = ss.y;
            npc.Z       = ss.z;
            npc.Heading = ss.heading;

            npcs.Add(t.NpcId, npc);
        }
Exemplo n.º 2
0
        internal void SetNpc(int id)
        {
            if (npcs == null)
            {
                npcs = new SortedList <int, L2Npc>();
            }

            NpcTemplate t   = new NpcTemplate(new StatsSet()); //NpcTable.Instance.GetNpcTemplate(id);
            L2Npc       npc = null;

            switch (t.NpcId)
            {
            case 35461:
                npc = new L2HideoutManager(this);
                break;

            case 35462:
                npc = new L2Doormen(this);
                break;
            }

            //npc.setTemplate(t);
            if (npc == null)
            {
                return;
            }

            StructureSpawn ss = StructureTable.Instance.GetSpawn(id);

            npc.X       = ss.X;
            npc.Y       = ss.Y;
            npc.Z       = ss.Z;
            npc.Heading = ss.Heading;

            npcs.Add(t.NpcId, npc);
        }
Exemplo n.º 3
0
        private static RoomObject DeepCopyRoomObject(RoomObject obj, Room room, Game game, Player user)
        {
            RoomObject copy = null;

            if (obj != null)
            {
                switch (obj.GetType().Name)
                {
                case "StructureSpawn":
                    var spawn = (StructureSpawn)obj;
                    copy = new StructureSpawn()
                    {
                        Game = game,
                        My   = spawn.Owner != null && spawn.Owner.ID == user.ID,
                        Pos  = room.GetPositionAt(spawn.Pos.X, spawn.Pos.Y),
                        Room = room,

                        Energy         = spawn.Energy,
                        EnergyCapacity = spawn.EnergyCapacity,
                        HitPoints      = spawn.HitPoints,
                        HitPointsMax   = spawn.HitPointsMax,
                        ID             = spawn.ID,
                        IsActive       = spawn.IsActive,
                        Name           = spawn.Name,
                        Owner          = spawn.Owner,
                        Spawning       = spawn.Spawning,
                        Type           = spawn.Type,
                        Memory         = new Dictionary <string, object>(),
                    };

                    game.Memory.Add(copy.ID, ((StructureSpawn)copy).Memory);

                    if (spawn.Memory != null)
                    {
                        foreach (string key in spawn.Memory.Keys)
                        {
                            ((StructureSpawn)copy).Memory.Add(key, room.Memory[key]);
                        }

                        ((StructureSpawn)copy).Memory["#"] = 2;
                    }
                    break;

                case "StructureController":
                    var controller = (StructureController)obj;
                    copy = new StructureController()
                    {
                        Game = game,
                        Room = room,

                        Owner = controller.Owner,
                        My    = controller.Owner != null && controller.Owner.ID == user.ID,

                        HitPoints    = controller.HitPoints,
                        HitPointsMax = controller.HitPointsMax,
                        ID           = controller.ID,
                        IsActive     = controller.IsActive,
                        Pos          = controller.Pos,
                        Type         = controller.Type,

                        Progress         = controller.Progress,
                        ProgressTotal    = controller.ProgressTotal,
                        Level            = controller.Level,
                        TicksToDowngrade = controller.TicksToDowngrade,
                    };
                    break;

                case "Source":
                    var source = (Source)obj;
                    copy = new Source()
                    {
                        Game = game,
                        Room = room,

                        Energy            = source.Energy,
                        EnergyCapacity    = source.EnergyCapacity,
                        ID                = source.ID,
                        Pos               = source.Pos,
                        TicksToRegenerate = source.TicksToRegenerate,
                    };
                    break;

                case "Creep":
                    var creep = (Creep)obj;

                    // TODO: Player-defined child class

                    copy = new Creep()
                    {
                        Game = game,
                        My   = (creep.Owner.ID == user.ID),
                        Room = room,

                        Body               = creep.Body,
                        Fatigue            = creep.Fatigue,
                        HitPoints          = creep.HitPoints,
                        HitPointsMax       = creep.HitPointsMax,
                        ID                 = creep.ID,
                        Name               = creep.Name,
                        NotifyWhenAttacked = creep.NotifyWhenAttacked,
                        Owner              = creep.Owner,
                        Pos                = creep.Pos,
                        Saying             = creep.Saying,
                        Spawning           = creep.Spawning,
                        TicksToLive        = creep.TicksToLive,

                        Memory    = new Dictionary <string, object>(),
                        _carrying = new Dictionary <ResourceTypes, int>(),
                    };

                    game.Memory.Add(copy.ID, ((Creep)copy).Memory);

                    foreach (string key in creep.Memory.Keys)
                    {
                        ((Creep)copy).Memory.Add(key, creep.Memory[key]);
                    }

                    ((Creep)copy).Memory["#"] = 2;

                    foreach (var key in creep._carrying.Keys)
                    {
                        ((Creep)copy)._carrying.Add(key, creep._carrying[key]);
                    }
                    break;

                default:
                    string type = obj.GetType().Name;
                    break;
                }
            }

            return(copy);
        }
Exemplo n.º 4
0
        private void ManageRoom(StructureSpawn spawn)
        {
            if (spawn.Spawning == null && spawn.Room.EnergyAvailable >= spawn.Room.EnergyCapacity)
            {
                // check creeps population
                int workerCount = spawn.Room.Creeps
                                  .Where(c => (string)c.Memory["Role"] == "worker")
                                  .Count();

                if (workerCount < (spawn.Room.Controller.Level * 2) ||
                    (spawn.Room.Controller.Level == 0 && workerCount == 0))
                {
                    var spawnInfo = spawn.SpawnCreep(new CreepInfo()
                    {
                        Body   = new BodyPartTypes[] { BodyPartTypes.Work, BodyPartTypes.Carry, BodyPartTypes.Move }.ToList(),
                        Memory = new Dictionary <string, object>()
                        {
                            { "Role", "worker" }, { "task", string.Empty }
                        },
                        DryRun = false,
                    });
                }
            }

            foreach (var creep in spawn.Room.Creeps)
            {
                // TODO: Switch to creep child classes
                switch (creep.Memory["Role"])
                {
                case "worker":

                    switch (creep.Memory["task"])
                    {
                    case "harvesting":
                        if (creep.CarryLoad < creep.CarryCapacity)
                        {
                            var source = spawn.Room.Objects.FirstOrDefault(o => o is Source) as Source;

                            if (creep.Harvest(source).TypeID == ResultTypes.TooFar)
                            {
                                creep.MoveTo(source);
                            }
                        }
                        else
                        {
                            // done w/ harvesting, find something else
                            creep.Memory["task"] = "harvest";

                            var targets = creep.Room.Objects
                                          .Where(o => typeof(StructureWithEnergy).IsAssignableFrom(o.GetType()))
                                          .Where(o => ((StructureWithEnergy)o).Energy < ((StructureWithEnergy)o).EnergyCapacity)
                                          .ToList();

                            if (targets != null && targets.Count > 0)
                            {
                                var target = targets.First();

                                if (creep.Transfer(target).TypeID == ResultTypes.TooFar)
                                {
                                    creep.MoveTo(target);
                                }
                            }
                        }
                        break;

                    default:                     // harvest
                        if (creep.CarryLoad == 0)
                        {
                            var source = spawn.Room.Objects.FirstOrDefault(o => o is Source) as Source;

                            if (source != null)
                            {
                                if (creep.Harvest(source).TypeID == ResultTypes.TooFar)
                                {
                                    creep.MoveTo(source);
                                }
                                else
                                {
                                    creep.Memory["task"] = "harvesting";
                                }
                            }
                        }
                        else
                        {
                            var targets = creep.Room.Objects
                                          .Where(o => typeof(StructureWithEnergy).IsAssignableFrom(o.GetType()))
                                          .Where(o => ((StructureWithEnergy)o).Energy < ((StructureWithEnergy)o).EnergyCapacity)
                                          .ToList();

                            if (targets != null && targets.Count > 0)
                            {
                                var target = targets.First();

                                if (creep.Transfer(target).TypeID == ResultTypes.TooFar)
                                {
                                    creep.MoveTo(target);
                                }
                            }
                            else if (creep.UpgradeController(creep.Room.Controller).TypeID == ResultTypes.TooFar)
                            {
                                creep.MoveTo(creep.Room.Controller);
                            }
                        }
                        break;
                    }

                    break;
                }
            }
        }
Exemplo n.º 5
0
 public SpawnCreep(StructureSpawn spawn, CreepInfo info)
 {
     CreepInfo = info;
     Spawn     = spawn;
 }