Inheritance: Building
示例#1
0
    void OnCollisionEnter(Collision collision)
    {
        Collider collider = collision.collider;

        if (collider.CompareTag("Player"))
        {
            AudioSource.PlayClipAtPoint(deathKnell, new Vector3(0, 3, 0));
            Instantiate(explosion, gameObject.transform.position, Quaternion.AngleAxis(-90, Vector3.right));
            PlayerObject.lives--;
            Debug.Log(PlayerObject.lives);

            if (PlayerObject.lives == 0)
            {
                collider.gameObject.SetActive(false);
                Destroy(gameObject);
                Alien.speed           = 0.0f;
                Alien.fallRate        = 1.0f;
                GameOver.isPlayerDead = true;
            }
        }
        else if (collider.CompareTag("Bunker"))
        {
            GameObject bunker = collider.gameObject;
            Bunker     b      = bunker.GetComponent <Bunker>();
            b.hp -= 1;
            Destroy(gameObject);
        }
    }
        public void Test_MakeBunkers()
        {
            var bunker = new Bunker(0, 560);

            var t = bunker.MakeBunkers();

            Assert.AreEqual(2, t.Count);
        }
 public void CreateBunkerGizmo(Bunker bunker)
 {
     var go = PrefabHelper.InstantiateAndReset(BunkerGizmoPrefab, transform);
     go.transform.position = bunker.transform.position.SetV3Y(0.1f);
     var gizmo = go.GetComponent<BunkerGizmo>();
     bunker.Gizmo = gizmo;
     gizmo.Init(bunker);
 }
        public void Setup()
        {
            GameObject bunkerGO = PoolManager.Instance.Spawn(Resources.Load("BunkerTest") as GameObject,
                                                             Vector3.zero, Quaternion.identity);
            GameObject sfxPlayerGO = MonoBehaviour.Instantiate(Resources.Load("SFXManagerTest") as GameObject,
                                                               Vector3.zero, Quaternion.identity);

            bunker = bunkerGO.GetComponent <Bunker>();
            bunker.Init();
        }
    public void CreateBunkerGizmo(Bunker bunker)
    {
        var go = PrefabHelper.InstantiateAndReset(BunkerGizmoPrefab, transform);

        go.transform.position = bunker.transform.position.SetV3Y(0.1f);
        var gizmo = go.GetComponent <BunkerGizmo>();

        bunker.Gizmo = gizmo;
        gizmo.Init(bunker);
    }
示例#6
0
    private static void Remove(Bunker bunker)
    {
        if (bunker.CurrentUsedSpace == 0)
        {
            result.Append($"{bunker.Name} -> Empty");
        }
        else
        {
            result.Append($"{bunker.Name} -> {string.Join(", ", bunker.Weapons)}");
        }

        result.Append(Environment.NewLine);
    }
示例#7
0
    public void Init(Bunker bunker)
    {
        Bunker = bunker;
        var length = bunker.SiteList.Length;

        SiteButtonList = new Button[length];
        for (var i = 0; i < length; i++)
        {
            var go = PrefabHelper.InstantiateAndReset(SiteButtonPrefab, transform);
            go.name = SiteButtonPrefab.name + i;
            go.transform.position = bunker.SiteList[i].Position.SetV3Y(0.1f);
            var button = go.GetComponent <Button>();
            var siteID = i;
            button.onClick.AddListener(bunker.SiteList[i].OnSiteClick);
            SiteButtonList[i] = button;
        }
    }
示例#8
0
 public override void SetComponent(Component comp)
 {
     if (comp.ClassId == display.ClassId)
     {
         display = (Display)comp;
     }
     else if (comp.ClassId == bunker.ClassId)
     {
         bunker = (Bunker)comp;
     }
     else if (comp.ClassId == pos.ClassId)
     {
         pos = (Position)comp;
     }
     else
     {
         throw new Exception("You passed a wrong component to the " + this.GetType().Name + " class");
     }
 }
示例#9
0
 public override void DisposeNode()
 {
     bunker  = null;
     display = null;
     pos     = null;
 }
示例#10
0
 public void Init(Bunker bunker, int id)
 {
     Bunker = bunker;
     ID = id;
 }
示例#11
0
	/// <summary>
	/// Elimina el bunker de la lista de bunkers
	/// </summary>
	/// <param name="bunker">Bunker.</param>
	public void DestroyBunker(Bunker bunker){
		bunkers.Remove (bunker);
	}
示例#12
0
    public Entity SpawnEntity(EntityBlueprint blueprint, Sector.LevelEntity data)
    {
        GameObject gObj = new GameObject(data.name);
        string     json = null;

        switch (blueprint.intendedType)
        {
        case EntityBlueprint.IntendedType.ShellCore:
        {
            ShellCore shellcore = gObj.AddComponent <ShellCore>();
            try
            {
                // Check if data has blueprint JSON, if it does override the current blueprint
                // this now specifies the path to the JSON file instead of being the JSON itself
                json = data.blueprintJSON;
                if (json != null && json != "")
                {
                    blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                    // try parsing directly, if that fails try fetching the entity file
                    try
                    {
                        JsonUtility.FromJsonOverwrite(json, blueprint);
                    }
                    catch
                    {
                        JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                          (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                    }

                    //Debug.Log(data.name);
                    blueprint.entityName = data.name;
                }
                else
                {
                    shellcore.entityName = blueprint.entityName = data.name;
                }

                if (current.type == Sector.SectorType.BattleZone)
                {
                    // add core arrow
                    if (MinimapArrowScript.instance && !(shellcore is PlayerCore))
                    {
                        shellcore.faction = data.faction;
                        MinimapArrowScript.instance.AddCoreArrow(shellcore);
                    }


                    // set the carrier of the shellcore to the associated faction's carrier
                    if (carriers.ContainsKey(data.faction))
                    {
                        shellcore.SetCarrier(carriers[data.faction]);
                    }

                    battleZone.AddTarget(shellcore);
                }
            }
            catch (System.Exception e)
            {
                Debug.Log(e.Message);
                //blueprint = obj as EntityBlueprint;
            }
            shellcore.sectorMngr = this;
            break;
        }

        case EntityBlueprint.IntendedType.PlayerCore:
        {
            if (player == null)
            {
                player            = gObj.AddComponent <PlayerCore>();
                player.sectorMngr = this;
            }
            else
            {
                Destroy(gObj);
                return(null);
            }

            break;
        }

        case EntityBlueprint.IntendedType.Turret:
        {
            gObj.AddComponent <Turret>();
            break;
        }

        case EntityBlueprint.IntendedType.Tank:
        {
            gObj.AddComponent <Tank>();
            break;
        }

        case EntityBlueprint.IntendedType.Bunker:
        {
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                var dialogueRef = blueprint.dialogue;
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }

                blueprint.dialogue = dialogueRef;
            }

            blueprint.entityName = data.name;
            Bunker bunker = gObj.AddComponent <Bunker>();
            stations.Add(bunker);
            bunker.vendingBlueprint =
                blueprint.dialogue != null
                        ? blueprint.dialogue.vendingBlueprint
                        : ResourceManager.GetAsset <VendingBlueprint>(data.vendingID);
            break;
        }

        case EntityBlueprint.IntendedType.Outpost:
        {
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                var dialogueRef = blueprint.dialogue;
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }
                blueprint.dialogue = dialogueRef;
            }

            blueprint.entityName = data.name;
            Outpost outpost = gObj.AddComponent <Outpost>();
            stations.Add(outpost);
            outpost.vendingBlueprint =
                blueprint.dialogue != null
                        ? blueprint.dialogue.vendingBlueprint
                        : ResourceManager.GetAsset <VendingBlueprint>(data.vendingID);
            break;
        }

        case EntityBlueprint.IntendedType.Tower:
        {
            break;
        }

        case EntityBlueprint.IntendedType.Drone:
        {
            Drone drone = gObj.AddComponent <Drone>();
            //drone.path = ResourceManager.GetAsset<Path>(data.pathID);
            break;
        }

        case EntityBlueprint.IntendedType.AirCarrier:
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }
            }

            blueprint.entityName = data.name;
            AirCarrier carrier = gObj.AddComponent <AirCarrier>();
            if (!carriers.ContainsKey(data.faction))
            {
                carriers.Add(data.faction, carrier);
            }
            carrier.sectorMngr = this;
            break;

        case EntityBlueprint.IntendedType.GroundCarrier:
            json = data.blueprintJSON;
            if (json != null && json != "")
            {
                blueprint = ScriptableObject.CreateInstance <EntityBlueprint>();

                // try parsing directly, if that fails try fetching the entity file
                try
                {
                    JsonUtility.FromJsonOverwrite(json, blueprint);
                }
                catch
                {
                    JsonUtility.FromJsonOverwrite(System.IO.File.ReadAllText
                                                      (resourcePath + "\\Entities\\" + json + ".json"), blueprint);
                }
            }

            blueprint.entityName = data.name;
            GroundCarrier gcarrier = gObj.AddComponent <GroundCarrier>();
            if (!carriers.ContainsKey(data.faction))
            {
                carriers.Add(data.faction, gcarrier);
            }
            gcarrier.sectorMngr = this;
            break;

        case EntityBlueprint.IntendedType.Yard:
            Yard yard = gObj.AddComponent <Yard>();
            yard.mode = BuilderMode.Yard;
            break;

        case EntityBlueprint.IntendedType.WeaponStation:
            gObj.AddComponent <WeaponStation>();
            break;

        case EntityBlueprint.IntendedType.CoreUpgrader:
            gObj.AddComponent <CoreUpgrader>();
            break;

        case EntityBlueprint.IntendedType.Trader:
            Yard trade = gObj.AddComponent <Yard>();
            trade.mode = BuilderMode.Trader;
            try
            {
                bool ok = true;
                if (blueprint.dialogue == null)
                {
                    ok = false;
                }
                if (blueprint.dialogue.traderInventory == null)
                {
                    ok = false;
                }
                if (data.blueprintJSON == null || data.blueprintJSON == "")
                {
                    ok = false;
                }
                if (ok)
                {
                    ShipBuilder.TraderInventory inventory = JsonUtility.FromJson <ShipBuilder.TraderInventory>(data.blueprintJSON);
                    if (inventory.parts != null)
                    {
                        blueprint.dialogue.traderInventory = inventory.parts;
                    }
                }
                else
                {
                    blueprint.dialogue.traderInventory = new List <EntityBlueprint.PartInfo>();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e);
                blueprint.dialogue.traderInventory = new List <EntityBlueprint.PartInfo>();
            }
            break;

        case EntityBlueprint.IntendedType.DroneWorkshop:
            Yard workshop = gObj.AddComponent <Yard>();
            workshop.mode = BuilderMode.Workshop;
            break;

        default:
            break;
        }
        Entity entity = gObj.GetComponent <Entity>();

        // TODO: These lines should perhaps be moved somewhere inside Entity itself, they need to run before even Awake is called
        if (!AIData.entities.Contains(entity))
        {
            AIData.entities.Add(entity);
        }
        entity.sectorMngr = this;
        entity.faction    = data.faction;
        entity.spawnPoint = entity.transform.position = data.position;
        entity.blueprint  = blueprint;

        if (entity as AirCraft && data.patrolPath != null && data.patrolPath.waypoints != null && data.patrolPath.waypoints.Count > 0)
        {
            // patrolling
            (entity as AirCraft).GetAI().setPath(data.patrolPath, null, true);
        }

        if (data.ID == "" || data.ID == null || (objects.ContainsKey(data.ID) && !objects.ContainsValue(gObj)))
        {
            data.ID = objects.Count.ToString();
        }
        entity.ID = data.ID;

        if (!objects.ContainsKey(data.ID))
        {
            objects.Add(data.ID, gObj);
        }
        return(entity);
    }
示例#13
0
 public BunkerSprite(Game game, Bunker bunker, Texture2D texture)
     : base(game)
 {
     this.bunker  = bunker;
     this.texture = texture;
 }
示例#14
0
 void Awake()
 {
     _bunker = GetComponent<Bunker>();
 }
示例#15
0
        static void GetDataFromFilesAndWriteToInflux(Configuration config)
        {
            string farmsFile          = config.SaveGameFolder + "farms.xml";
            string itemsFile          = config.SaveGameFolder + "items.xml";
            string environmentFile    = config.SaveGameFolder + "environment.xml";
            string seasonsFile        = config.SaveGameFolder + "seasons.xml";
            string careerSavegameFile = config.SaveGameFolder + "careerSavegame.xml";

            // Is there a seasons.xml file?
            bool hasSeasons = File.Exists(seasonsFile);

            XPathDocument  farmsDoc = new XPathDocument(farmsFile);
            XPathNavigator farmsNav = farmsDoc.CreateNavigator();

            XPathDocument  itemsDoc = new XPathDocument(itemsFile);
            XPathNavigator itemsNav = itemsDoc.CreateNavigator();

            XPathDocument  environmentDoc = new XPathDocument(environmentFile);
            XPathNavigator environmentNav = environmentDoc.CreateNavigator();

            XPathDocument  careerSavegameDoc = new XPathDocument(careerSavegameFile);
            XPathNavigator careerSavegameNav = careerSavegameDoc.CreateNavigator();

            XPathDocument  seasonsDoc = new XPathDocument(seasonsFile);
            XPathNavigator seasonsNav = seasonsDoc.CreateNavigator();

            // Get the savegameName
            string savegameName = careerSavegameNav.SelectSingleNode("/careerSavegame/settings/savegameName").Value;

            // Get the mapTitle
            string mapTitle = careerSavegameNav.SelectSingleNode("/careerSavegame/settings/mapTitle").Value;

            // Get the environment.xml day
            int.TryParse(environmentNav.SelectSingleNode("/environment/currentDay").ToString(), out int currentDay);

            // Get the days per season
            int.TryParse(seasonsNav.SelectSingleNode("/seasons/environment/daysPerSeason").ToString(), out int daysPerSeason);

            // Get the currentDayOffset
            int.TryParse(seasonsNav.SelectSingleNode("/seasons/environment/currentDayOffset").ToString(), out int currentDayOffset);

            // Calculate the Seasons day
            int daysInYear = daysPerSeason * 4;
            int seasonsDay = currentDay + currentDayOffset;
            int dayInYear  = seasonsDay % daysInYear;


            Console.WriteLine("{0} Read farm sim data", DateTime.Now);

            Dictionary <string, float>           allSilos           = new Dictionary <string, float>();
            Dictionary <string, Bunker>          allBunkerSiloes    = new Dictionary <string, Bunker>();
            Dictionary <string, AnimalHusbandry> allAnimalHusbandry = new Dictionary <string, AnimalHusbandry>();
            // Get all items
            XPathNodeIterator items = itemsNav.Select("/items/item");

            foreach (XPathNavigator item in items)
            {
                // Check for silos that I own.
                if (item.GetAttribute("className", "") == "SiloPlaceable" && item.GetAttribute("farmId", "") == config.FarmID.ToString())
                {
                    // Get all the storage nodes
                    XPathNodeIterator storageNodes = item.Select("storage/node");
                    foreach (XPathNavigator storageNode in storageNodes)
                    {
                        if (!allSilos.ContainsKey(storageNode.GetAttribute("fillType", "")))
                        {
                            float.TryParse(storageNode.GetAttribute("fillLevel", "").Replace('.', ','), out float fillLevel);
                            allSilos.Add(storageNode.GetAttribute("fillType", ""), fillLevel);
                        }
                        else
                        {
                            float.TryParse(storageNode.GetAttribute("fillLevel", ""), out float fillLevel);
                            allSilos[storageNode.GetAttribute("fillType", "")] += fillLevel;
                        }
                    }
                }

                // Bunker siloes, regardless of ownership. Some of the built in ones for a map are not farm owned but you can still use them
                if (item.GetAttribute("className", "") == "BunkerSiloPlaceable")
                {
                    XPathNodeIterator bunkerSiloes = item.Select("bunkerSilo");
                    foreach (XPathNavigator bs in bunkerSiloes)
                    {
                        // We use position to make an ID, since ID changes with items in game. So there is no ID persistance.
                        // It is however extremly unlikely that any bunker will have the exact same X coord as something else.
                        string BunkerSiloPosition = item.GetAttribute("position", "");
                        string firstCoord         = BunkerSiloPosition.Split(' ')[0].Split('.')[0];
                        int.TryParse(firstCoord, out int BunkerSiloId);
                        BunkerSiloId = Math.Abs(BunkerSiloId);

                        Bunker thisBunker = new Bunker();
                        int.TryParse(bs.GetAttribute("state", ""), out thisBunker.state);
                        float.TryParse(bs.GetAttribute("fillLevel", "").Replace('.', ','), out thisBunker.fillLevel);
                        float.TryParse(bs.GetAttribute("compactedFillLevel", "").Replace('.', ','), out thisBunker.compactedFillLevel);
                        float.TryParse(bs.GetAttribute("fermentingTime", "").Replace('.', ','), out thisBunker.fermentingTime);

                        // Also combine the id with the poit index for each pit.
                        allBunkerSiloes.Add(BunkerSiloId + "_" + bs.GetAttribute("index", ""), thisBunker);
                    }
                }


                // Animals
                if (item.GetAttribute("className", "") == "AnimalHusbandry" && item.GetAttribute("farmId", "") == config.FarmID.ToString())
                {
                    AnimalHusbandry thisAnimalHusbandry = new AnimalHusbandry();

                    // We use position to make an ID
                    string AnimalHusbandryPosition = item.GetAttribute("position", "");
                    string firstCoord = AnimalHusbandryPosition.Split(' ')[0].Split('.')[0];
                    int.TryParse(firstCoord, out int AnimalHusbandryId);
                    AnimalHusbandryId = Math.Abs(AnimalHusbandryId);

                    // Get all the modules
                    XPathNodeIterator modules = item.Select("module");
                    foreach (XPathNavigator module in modules)
                    {
                        // NOTE: manure is not possible to track in this way, because it is not stored in the save file as part of the Husbandry building.
                        switch (module.GetAttribute("name", ""))
                        {
                        case "milk":
                            float.TryParse(module.SelectSingleNode("fillLevel").GetAttribute("fillLevel", "").Replace('.', ','), out thisAnimalHusbandry.milk);
                            break;

                        case "liquidManure":
                            float.TryParse(module.SelectSingleNode("fillLevel").GetAttribute("fillLevel", "").Replace('.', ','), out thisAnimalHusbandry.slurry);
                            break;

                        case "animals":
                            XPathNodeIterator animals = module.Select("animal");
                            thisAnimalHusbandry.animal = animals.Count;
                            break;

                        default:
                            break;
                        }
                    }
                    allAnimalHusbandry.Add(AnimalHusbandryId.ToString(), thisAnimalHusbandry);
                }
            }

            // Get the price of things from the seasons historical plot
            XPathNavigator priceHistory = seasonsNav.SelectSingleNode("/seasons/economy/history");

            XPathNodeIterator fillTypes = priceHistory.Select("fill");

            Dictionary <string, float[]> historyPrices = new Dictionary <string, float[]>();

            foreach (XPathNavigator fill in fillTypes)
            {
                string   fillTypeKey  = fill.GetAttribute("fillType", "");
                string[] stringValues = fill.SelectSingleNode("values").Value.Replace('.', ',').Split(';');
                float[]  values       = new float[stringValues.Length];

                for (int i = 0; i < stringValues.Length; i++)
                {
                    float.TryParse(stringValues[i], out values[i]);
                }

                historyPrices.Add(fillTypeKey, values);
            }

            // Setup InfluxDBClient
            // This is a lazy client and does not connect untill you ask it to actually do something.
            InfluxDbClient influxClient = new InfluxDbClient(
                config.GetInfluxEndpoint(),
                config.InfluxUser,
                config.InfluxPassword,
                InfluxDbVersion.Latest);

            List <Point> point = new List <Point>();

            foreach (string key in allSilos.Keys)
            {
                Point thisPoint = new Point();
                thisPoint.Name = "siloLevels";
                thisPoint.Tags = new Dictionary <string, object>()
                {
                    { "savegameName", savegameName },
                    { "mapTitle", mapTitle },
                    { "fillType", key }
                };
                thisPoint.Fields = new Dictionary <string, object>()
                {
                    { "level", allSilos[key] },
                    { "price", historyPrices[key][dayInYear - 1] }
                };
                point.Add(thisPoint);
            }
            foreach (string key in allBunkerSiloes.Keys)
            {
                Point thisPoint = new Point();
                thisPoint.Name = "bunkerSiloes";
                thisPoint.Tags = new Dictionary <string, object>()
                {
                    { "id", key },
                    { "savegameName", savegameName },
                    { "mapTitle", mapTitle }
                };
                thisPoint.Fields = new Dictionary <string, object>()
                {
                    { "fillLevel", allBunkerSiloes[key].fillLevel },
                    { "compactedFillLevel", allBunkerSiloes[key].compactedFillLevel },
                    { "fermentingTime", allBunkerSiloes[key].fermentingTime },
                    { "state", allBunkerSiloes[key].state }
                };

                point.Add(thisPoint);
            }
            foreach (string key in allAnimalHusbandry.Keys)
            {
                Point thisPoint = new Point();
                thisPoint.Name = "animals";
                thisPoint.Tags = new Dictionary <string, object>()
                {
                    { "id", key },
                    { "savegameName", savegameName },
                    { "mapTitle", mapTitle }
                };
                thisPoint.Fields = new Dictionary <string, object>()
                {
                    { "milk", allAnimalHusbandry[key].milk },
                    { "slurry", allAnimalHusbandry[key].slurry },
                    { "animals", allAnimalHusbandry[key].animal }
                };
                point.Add(thisPoint);
            }

            Point daypoint = new Point();

            daypoint.Name = "days";
            daypoint.Tags = new Dictionary <string, object>()
            {
                { "savegameName", savegameName },
                { "mapTitle", mapTitle }
            };
            daypoint.Fields = new Dictionary <string, object>()
            {
                { "daysPerSeason", daysPerSeason },
                { "dayInYear", dayInYear },
                { "currentDay", currentDay },
                { "daysInYear", daysInYear },
                { "seasonsDay", seasonsDay }
            };
            point.Add(daypoint);

            var result = influxClient.Client.WriteAsync(point, "farmingsim").GetAwaiter().GetResult();
        }
示例#16
0
    public static void Main()
    {
        int            bunkerTotalCapacity = int.Parse(Console.ReadLine());
        Queue <Bunker> bunkers             = new Queue <Bunker>();

        //  Dictionary<string, List<int>> bunkers = new Dictionary<string, List<int>>();

        string input;

        while ((input = Console.ReadLine()) != "Bunker Revision")
        {
            string[] tokens   = input.Split();
            Regex    alphabet = new Regex(@"[A-Z]+|[a-z]+");

            foreach (var token in tokens)
            {
                if (alphabet.IsMatch(token))
                {
                    bunkers.Enqueue(new Bunker(token));
                    continue;
                }
                int weapon = int.Parse(token);

                if (weapon > bunkerTotalCapacity)
                {
                    continue;
                }

                if (bunkers.Count != 0)
                {
                    if (bunkers.Count != 1)
                    {
                        int cnt = bunkers.Count;

                        while (cnt != 0)
                        {
                            cnt--;

                            var currentBunker = bunkers.Dequeue();

                            if (bunkerTotalCapacity - currentBunker.TotalSumOfWeapons <= weapon)
                            {
                                currentBunker.Weapons.Enqueue(weapon);

                                if (currentBunker.TotalSumOfWeapons == bunkerTotalCapacity)
                                {
                                    Console.WriteLine(currentBunker.Name + " -> " + string.Join(", ", currentBunker.Weapons));
                                    break;
                                }

                                bunkers.Enqueue(currentBunker);
                            }
                        }
                    }

                    else
                    {
                        Bunker theOnlyBunker = bunkers.Dequeue();

                        if (bunkerTotalCapacity >= weapon)
                        {
                            if (bunkerTotalCapacity - theOnlyBunker.TotalSumOfWeapons >= weapon)
                            {
                                theOnlyBunker.Weapons.Enqueue(weapon);
                            }
                            else
                            {
                                while (bunkerTotalCapacity - theOnlyBunker.TotalSumOfWeapons < weapon)
                                {
                                    theOnlyBunker.Weapons.Dequeue();
                                }
                                theOnlyBunker.Weapons.Enqueue(weapon);
                            }

                            bunkers.Enqueue(theOnlyBunker);
                        }
                    }
                }
            }
        }
    }
示例#17
0
 public override void SetUp()
 {
     bunker  = new Bunker();
     display = new Display();
     pos     = new Position();
 }
示例#18
0
 private void Start()
 {
     bunker         = GetComponent <Bunker>();
     damageSystem   = GetComponent <BunkerDamageSystem>();
     attackCooldown = bunker.attackCooldown;
 }
示例#19
0
 void Awake()
 {
     _bunker = GetComponent <Bunker>();
 }
示例#20
0
        public static string GetBunkerThumbnailPath(Bunker bunker)
        {
            string fileName = Path.GetFileNameWithoutExtension(bunker.ImageUri);

            return("/img/Layout/" + fileName + ".png");
        }
示例#21
0
 private void Start()
 {
     bunker = GetComponent <Bunker>();
 }
示例#22
0
 public void Init(Bunker bunker, int id)
 {
     Bunker = bunker;
     ID     = id;
 }
示例#23
0
 private void Awake()
 {
     instance = this;
 }
示例#24
0
 public static string GetBunkerPath(Bunker bunker)
 {
     return(GetRootPath() + "/Bunker/" + bunker.ImageUri);
 }
示例#25
0
    public List <Enemy> BuildLevel(LevelConfig levelConfig)
    {
        // Player
        GameObject    player        = PoolManager.Instance.Spawn(playerPrefab, playerStartingPos, Quaternion.identity);
        MainCharacter playerManager = player.GetComponent <MainCharacter>();

        if (levelConfig.playerConfig != null)
        {
            playerManager.SetData(levelConfig.playerConfig);
        }

        Player = playerManager;

        // Enemies
        enemies = new Enemy[levelConfig.enemiesPerColumn, levelConfig.enemiesPerRow];
        float horizontalStep = (enemyEndPos.x - enemyStartingPos.x) / (levelConfig.enemiesPerRow - 1);
        float verticalStep   = (enemyEndPos.y - enemyStartingPos.y) / (levelConfig.enemiesPerColumn - 1);

        Debug.Log("LevelBuilder: Horizontal Step: " + horizontalStep + ", Vertical Step: " + verticalStep);

        for (int i = 0; i < levelConfig.enemiesPerColumn; i++)
        {
            for (int j = 0; j < levelConfig.enemiesPerRow; j++)
            {
                Vector3 enemyPos = enemyStartingPos + new Vector3(horizontalStep * j, verticalStep * i);

                GameObject newEnemyGO = PoolManager.Instance.Spawn(enemyPrefab, enemyPos, Quaternion.identity);
                Enemy      newEnemy   = newEnemyGO.GetComponent <Enemy>();

                if (levelConfig.enemyConfig != null)
                {
                    newEnemy.SetData(levelConfig.enemyConfig, new Vector2Int(i, j));
                }

                // Add to array for easier handling of neighbours
                enemies[i, j] = newEnemy;
                enemyList.Add(newEnemy);
            }
        }

        horizontalStep = bunkerStartingPos.x * 2 / (numberOfBunkers - 1);
        // Bunkers
        for (int i = 0; i < numberOfBunkers; i++)
        {
            Vector3 bunkerPos = bunkerStartingPos - new Vector3(horizontalStep * i, 0);

            GameObject newBunkerGO = PoolManager.Instance.Spawn(bunkerPrefab, bunkerPos, Quaternion.identity);
            Bunker     newBunker   = newBunkerGO.GetComponent <Bunker>();
            newBunker.Init();
            bunkerList.Add(newBunker);
        }

        // Set neighbours of enemies
        for (int i = 0; i < levelConfig.enemiesPerColumn; i++)
        {
            for (int j = 0; j < levelConfig.enemiesPerRow; j++)
            {
                if (i > 0)
                {
                    enemies[i, j].neighbours.Add(enemies[i - 1, j]);
                }
                if (i < levelConfig.enemiesPerColumn - 1)
                {
                    enemies[i, j].neighbours.Add(enemies[i + 1, j]);
                }
                if (j > 0)
                {
                    enemies[i, j].neighbours.Add(enemies[i, j - 1]);
                }
                if (j < levelConfig.enemiesPerRow - 1)
                {
                    enemies[i, j].neighbours.Add(enemies[i, j + 1]);
                }
            }
        }

        return(enemyList);
    }