Пример #1
0
        private static bool IsDoingTheThing(ICreep creep, string theThing)
        {
            if (!thingy.ContainsKey(creep.name))
            {
                thingy[creep.name] = false;
            }

            if (creep.store[Resource.energy] == 0)
            {
                thingy[creep.name] = false;
            }
            if (creep.store.GetFreeCapacity(Resource.energy) == 0)
            {
                thingy[creep.name] = true;
            }

            //	Game.WriteLine(thingy[theThing]ng() ?? "nult");
            //todo: this will need to be updated when I write a proper memory object

            return(thingy[creep.name]);
            //if (creep.store[Resource.energy] == 0) { creep.memory[theThing] = false; }
            //if (creep.store.GetFreeCapacity() == 0) { creep.memory[theThing] = true; }

            //Game.WriteLine(creep.memory[theThing]?.ToString() ?? "nult");
            ////todo: this will need to be updated when I write a proper memory object

            //return (bool?)creep.memory[theThing] ?? false;
        }
Пример #2
0
        public static bool TryGetCreepOrSpawn(string name, out ICreep creep, Bodypart[] parts, ISpawn spawn)
        {
            if (Game.instance.creeps.TryGetValue(name, out creep))
            {
                return(true);
            }

            Log(spawn?.SpawnCreep(parts, name).ToString() ?? "-42");

            return(false);
        }
Пример #3
0
        public static void Upgrader(ICreep creep)
        {
            if (!IsDoingTheThing(creep, "upgrading"))
            {
                ActionHavest(creep);
                return;
            }

            creep.Say("⚡ upgrade", true);

            if (creep.UpgradeController(creep.room.controller) != Result.errNotInRange)
            {
                return;
            }
            creep.MoveTo(creep.room.controller);
        }
Пример #4
0
        public static void ActionHavest(ICreep creep)
        {
            creep.Say("🔄 harvest", true);

            var sources = creep.room.Find(Find.sources);
            var result  = creep.Harvest((ISource)sources[0]);

            switch (result)
            {
            case Result.errNotInRange:
                creep.MoveTo(sources[0]);
                break;

            case Result.ok: break;
            }
        }
Пример #5
0
        public static void Harvester(ICreep creep)
        {
            if (!IsDoingTheThing(creep, "filling"))
            {
                ActionHavest(creep);
                return;
            }

            creep.Say("⛽ fill", true);

            var found  = creep.room.Find(Find.structures);
            var target = found.FirstOrDefault(o =>
            {
                switch ((o as IStructure)?.structureType)
                {
                case StructureType.spawn:
                case StructureType.extension:
                case StructureType.tower:
                    return(((o as IHasStore)?.store.GetFreeCapacity(Resource.energy) ?? 0) > 0);

                default: return(false);
                }
            }
                                              );

            if (target == null)
            {
                return;
            }

            var result = creep.Transfer((IHasStore)target, Resource.energy);

            switch (result)
            {
            case Result.errNotInRange:
                creep.MoveTo(target);
                break;

            case Result.ok: break;

            default:
                creep.Say(result.ToString());
                break;
            }
        }
Пример #6
0
        public static void Builder(ICreep creep)
        {
            if (!IsDoingTheThing(creep, "building"))
            {
                ActionHavest(creep);
                return;
            }

            creep.Say("🚧 build", true);

            var targets = creep.room.Find(Find.constructionSites);

            if (targets.Length == 0)
            {
                return;
            }

            if (creep.Build((IConstructionSite)targets[0]) != Result.errNotInRange)
            {
                return;
            }
            creep.MoveTo(targets[0]);
        }