예제 #1
0
        protected override void ClickFirst()
        {
            string moveTyp = ((UnitInfo)mapElementInfo).dataUnit.movement;
            int    cost    = GameMgmt.Get().newMap.PathFinding(mapElementInfo.Pos().level).Cost(player, moveTyp, mapElementInfo.Pos(), new NVector(LastClickPos.x, LastClickPos.y, mapElementInfo.Pos().level));

            OnMapUI.Get().unitUI.ShowPanelMessage($"You want to move to this field for {cost} AP? Click again!");
        }
예제 #2
0
        public override bool Check(string data, Player player, NVector pos)
        {
            string[]    d    = data.Split(';');
            DataTerrain terr = GameMgmt.Get().newMap.Terrain(pos);

            return(terr.id == d[2]);
        }
예제 #3
0
        public static AnimationObject Create(NVector pos)
        {
            var ani = Instantiate(UIElements.Get().animationHelper, GameMgmt.Get().newMap[pos.level].effects.transform).GetComponent <AnimationObject>();

            ani.transform.position = new Vector3(pos.x + 0.5f, pos.y + 0.5f);
            return(ani);
        }
예제 #4
0
        public void UpdatePanel()
        {
            //remove actions
            UIHelper.ClearChild(infoButtons);

            bool found = false;

            //add new
            foreach (Info info in S.ActPlayer().info.infos)
            {
                if (info.round != GameMgmt.Get().gameRound.Round)
                {
                    break;
                }

                if (info.read)
                {
                    continue;
                }

                AddInfoButton(info);
                found = true;
            }

            //
            if (!found)
            {
                ShowTown();
            }
        }
예제 #5
0
        protected virtual void CreateTile(GameMapDataLevel std, int x, int y, int layer, int[][] layerData, int height,
                                          DataTerrain invisible)
        {
            int oTerrain = std.At(new Vector3Int(x, y, layer));

            if (oTerrain == -1)
            {
                layerData[height - y - 1][x] = -1;
                return;
            }

            DataTerrain org = L.b.terrains[oTerrain];

            //has element?
            try
            {
                if (mapGeneration.terrains.ContainsKey(org.id))
                {
                    layerData[height - y - 1][x] = L.b.terrains[mapGeneration.terrains[org.id]].defaultTile;
                }
                else if (layer == 0)
                {
                    layerData[height - y - 1][x] = invisible.defaultTile;
                }
                else
                {
                    layerData[height - y - 1][x] = -1;
                }
            }
            catch (Exception e)
            {
                Debug.Log($"{y}/{height - y - 1}/{height},{x}/{GameMgmt.Get().data.map.width}");
                throw e;
            }
        }
예제 #6
0
        public UnitInfo Create(int player, string type, NVector pos, Dictionary <string, int> cost = null)
        {
            //exist?
            if (!L.b.units.ContainsKey(type))
            {
                throw new MissingComponentException("Unit " + type + " not exist");
            }

            if (!pos.Valid())
            {
                throw new MissingComponentException("not a valid position");
            }

            if (At(pos) != null)
            {
                throw new MissingComponentException($"field {pos} is blocked");
            }

            UnitInfo ui = Instantiate(unitPrefab, GameMgmt.Get().newMap.levels[pos.level].units.transform);

            ui.Init(type, player, pos, cost ?? new Dictionary <string, int>(L.b.units[type].cost));
            ui.NextRound();
            units.Add(ui);
            GameMgmt.Get().data.units.Add(ui.data);
            return(ui);
        }
예제 #7
0
        /// <summary>
        /// Get a start position or an exception
        /// </summary>
        /// <param name="nation"></param>
        /// <returns></returns>
        /// <exception cref="System.MissingMemberException"></exception>
        public NVector GetStartPos(string nation)
        {
            GameMapData gmap = GameMgmt.Get().data.map;

            Nation n = L.b.nations[nation];
            int    i = 0;

            while (i < 1000)
            {
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = _map.Terrain(new NVector(x, y, gmap.standard));

                //right terrain?
                //TODO  && t.visible > 0
                if (t.id == n.Terrain || (t.MoveCost("walk") > 0 && t.MoveCost("walk") <= 10))
                {
                    //has a unit?
                    if (S.Unit().Free(new NVector(x, y, gmap.standard)))
                    {
                        //TODO find right spot with level support
                        return(new NVector(x, y, gmap.standard));
                    }
                }

                i++;
            }

            Debug.Log($"{gmap.standard}/{gmap.levels.Count}");

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position for {nation} using {pos}");
            return(pos);
        }
예제 #8
0
        private bool FindPos(Player player, UnitInfo unit, NVector pos, ActionHolder holder)
        {
            if (holder.data.ContainsKey("pos"))
            {
                return(true);
            }
            DataUnit dUnit = unit.dataUnit;

            //find next field
            foreach (var p in CircleGenerator.Gen(pos, unit.data.apMax / 5 * 2))
            {
                if (AddGoal(unit, holder, p))
                {
                    return(true);
                }
            }

            //has nothing?
            //search the whole map
            for (int x = 0; x < GameMgmt.Get().data.map.width; x++)
            {
                for (int y = 0; y < GameMgmt.Get().data.map.height; y++)
                {
                    if (AddGoal(unit, holder, new NVector(x, y, pos.level)))
                    {
                        return(true);
                    }
                }
            }

            //has a field?
            unit.SetLastInfo(S.T("actionRepeatErrorDestination", holder.DataAction().Name()));
            unit.SetWaitingAction(null);
            return(false);
        }
예제 #9
0
    void Update()
    {
        if (!aimingMode)
        {
            return;
        }

        Vector3 mousePos2D = Input.mousePosition;

        mousePos2D.z = -Camera.main.transform.position.z;
        Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D);

        Vector3 mouseDelta = mousePos3D - launchPos;

        float maxMagnitude = this.GetComponent <SphereCollider>().radius;

        if (mouseDelta.magnitude > maxMagnitude)
        {
            mouseDelta.Normalize();
            mouseDelta *= maxMagnitude;
        }

        Vector3 projPos = launchPos + mouseDelta;

        projectile.transform.position = projPos;

        if (Input.GetMouseButtonUp(0))
        {
            aimingMode = false;
            projectilRigidbody.isKinematic = false;
            projectilRigidbody.velocity    = -mouseDelta * velocityMult;
            projectile = null;
            GameMgmt.ShotFired();
        }
    }
예제 #10
0
파일: GameMap.cs 프로젝트: TrutzX/9Nations
        public IEnumerator LoadMap()
        {
            yield return(GameMgmt.Get().load.ShowSubMessage($"Loading Map data"));

            //load Map
            yield return(CreateLayers());
        }
예제 #11
0
        public virtual WindowBuilderSplit ShowInfoWindow()
        {
            WindowBuilderSplit win = WindowBuilderSplit.Create(gameObject.name, null);

            win.Add(new ActionDisplaySplitElement(this));
            win.Add(new TerrainSplitElement(GameMgmt.Get().newMap.Terrain(Pos()), Pos()));
            if (data.townId != -1)
            {
                win.Add(new CameraTownSplitElement(win, Town()));
            }
            if (S.Debug())
            {
                win.Add(new DebugMapElementSplitElement(this));
                win.Add(new DebugSpellSplitElement(this));
            }

            if (L.b.improvements.Has(Pos()))
            {
                win.Add(new LexiconSplitElement(L.b.improvements.At(Pos())));
            }

            win.Add(new InfosSplitElement(data.info));

            return(win);
        }
예제 #12
0
        public override bool NextRound()
        {
            data.ap = data.apMax;
            data.BuildingUpdate();
            Town t = Town();

            if (!base.NextRound())
            {
                return(false);
            }

            //need to change icon?

            //todo change dyn
            bool winter = GameMgmt.Get().gameRound.IsSeason("winter");

            //is no change
            if (isWinter == winter)
            {
            }
            //change to summer?
            else if (isWinter && !winter)
            {
                isWinter = false;
                FinishInit();
            }
            //change to winter?
            else if (!isWinter && winter)
            {
                isWinter = true;
                FinishInit();
            }

            return(true);
        }
예제 #13
0
파일: UnitInfo.cs 프로젝트: TrutzX/9Nations
        public string Passable(NVector pos)
        {
            DataTerrain land = GameMgmt.Get().newMap.Terrain(pos);

            //check terrain
            int cost = GameMgmt.Get().newMap.PathFinding(Pos().level).Cost(Player(), dataUnit.movement, Pos(), pos);

            if (cost == 0)
            {
                return(S.T("unitMoveErrorPassable", land.Name()));
            }

            //visible?
            if (!Player().fog.Visible(pos))
            {
                return(S.T("unitMoveErrorExplored", land.Name()));
            }

            //another unit?
            if (!S.Unit().Free(pos))
            {
                return(S.T("unitMoveErrorUnit", land.Name(), S.Unit().At(pos).name));
            }

            //can walk
            if (cost > data.ap)
            {
                return(S.T("unitMoveErrorAp", land.Name(), cost - data.ap));
            }

            return(null);
        }
예제 #14
0
파일: UnitInfo.cs 프로젝트: TrutzX/9Nations
 /// <summary>
 /// Destroy this unit
 /// </summary>
 public override void Kill()
 {
     GameMgmt.Get().data.units.Remove(data);
     GameMgmt.Get().unit.units.Remove(this);
     Destroy(gameObject);
     Debug.Log($"Kill unit {name} at {Pos()}");
 }
예제 #15
0
        protected virtual NVector CreateNewSpot()
        {
            GameMapData      gmap = GameMgmt.Get().data.map;
            GameMapDataLevel gmdl = GameMgmt.Get().data.map.levels[gmap.standard];

            int i = 0;

            while (i < 1000)
            {
                i++;
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = gmdl.Terrain(x, y);

                if (t.MoveCost("walk") == 0 || t.MoveCost("walk") > 10)
                {
                    continue;                                                     // can walk?
                }
                if (!gmdl.TerrainNear(x, y, "water", 2))
                {
                    continue;                                      //near water?
                }
                if (!S.Unit().Free(new NVector(x, y, gmap.standard)))
                {
                    continue;                                                 //near water?
                }
                return(new NVector(x, y, gmap.standard));
            }

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position using {pos}");
            return(pos);
        }
예제 #16
0
파일: UnitInfo.cs 프로젝트: TrutzX/9Nations
        public void MoveTo(NVector pos, bool moveCamera = true)
        {
            //change level?
            if (data.pos.level != pos.level)
            {
                transform.SetParent(GameMgmt.Get().newMap[pos.level].units.transform);
            }

            if (moveCamera)
            {
                //new level?
                if (data.pos.level != pos.level)
                {
                    S.CameraMove().MoveTo(pos);
                }
                else
                {
                    MoveBy(pos.x - Pos().x, pos.y - Pos().y);
                    return;
                }
            }
            data.pos           = pos;
            transform.position = new Vector2(Pos().x + 0.5f, Pos().y);
            Clear(pos);
        }
예제 #17
0
        public void NextRound()
        {
            //todo change dyn
            bool winter = GameMgmt.Get().gameRound.IsSeason("winter");

            //is no change
            if (dataLevel.isWinter == winter)
            {
                return;
            }

            //change to summer?
            if (dataLevel.isWinter && !winter)
            {
                layersWinter.ForEach(w => w.gameObject.SetActive(false));
                layers.ForEach(w => w.gameObject.SetActive(true));
                dataLevel.isWinter = false;
                return;
            }

            //change to winter?
            if (!dataLevel.isWinter && winter)
            {
                layersWinter.ForEach(w => w.gameObject.SetActive(true));
                layers.ForEach(w => w.gameObject.SetActive(false));
                dataLevel.isWinter = true;
            }
        }
예제 #18
0
파일: Modifier.cs 프로젝트: TrutzX/9Nations
        public double CalcModi(double standard, Player player, NVector pos)
        {
            int proc = 0;
            int val  = 0;

            Check(S.Game().data.modi, player, pos, ref val, ref proc);
            Check(player.Modi, player, pos, ref val, ref proc);
            Check(player.Nation().Modi, player, pos, ref val, ref proc);
            Check(GameMgmt.Get().newMap.Terrain(pos).modi, player, pos, ref val, ref proc);
            Check(GameMgmt.Get().gameRound.Modi(), player, ref val, ref proc);
            if (L.b.improvements.Has(pos))
            {
                Check(L.b.improvements.At(pos).modi, player, pos, ref val, ref proc);
            }

            if (S.Building(pos) != null)
            {
                Check(S.Building(pos).dataBuilding.modi, player, pos, ref val, ref proc);
            }

            //calc
            standard += (standard * proc) / 100;
            standard += val;
            return(Math.Max(0, standard));
        }
예제 #19
0
        public void ShowRes(PanelBuilder panel, Player player, NVector pos)
        {
            //addHeader
            if (pos != null && GameMgmt.Get().data.map.levels[pos.level].ResGenKey(pos.x, pos.y) != null && player != null && player.overlay.Get("res", pos) == 1)
            {
                panel.AddHeaderLabelT("res");
                foreach (string key in GameMgmt.Get().data.map.levels[pos.level].ResGenKey(pos.x, pos.y))
                {
                    if (S.Debug())
                    {
                        panel.AddHeaderLabel(key);
                        panel.AddInput(key, GameMgmt.Get().data.map.ResGen(pos, key),
                                       val => GameMgmt.Get().data.map.ResGenAdd(pos, key, val - GameMgmt.Get().data.map.ResGen(pos, key)));
                        continue;
                    }
                    L.b.res[key].AddImageLabel(panel, L.b.terrains.GenDesc(GameMgmt.Get().data.map.ResGen(pos, key)));
                }
                return;
            }

            if (res.Count > 0)
            {
                panel.AddHeaderLabelT("resInclude");
                foreach (KeyValuePair <string, string> r in res)
                {
                    int    chance = ResChance(r.Key);
                    var    c      = ResRange(r.Key);
                    string txt    = S.T("resCountRange", L.b.terrains.GenDesc(c.min), L.b.terrains.GenDesc(c.max));
                    L.b.res[r.Key].AddImageLabel(panel, chance >= 1 ? S.T("resCountChance", chance, txt) : txt);
                }
            }
        }
예제 #20
0
        public Tile Tile(int id, Color color)
        {
            var t = GameMgmt.Get().newMap.tools.GetTile(Icon.Replace("4", id.ToString()), color.ToString());

            t.color = color;
            return(t);
        }
예제 #21
0
        public BuildingInfo Create(int town, string type, NVector pos, Dictionary <string, int> cost = null)
        {
            //exist?
            if (!L.b.buildings.ContainsKey(type))
            {
                throw new MissingComponentException($"Building {type} not exist");
            }

            if (!pos.Valid())
            {
                throw new MissingComponentException("not a valid position");
            }

            if (At(pos) != null)
            {
                throw new MissingComponentException($"field {pos} is blocked");
            }

            BuildingInfo bi = Instantiate(buildPrefab, GameMgmt.Get().newMap.levels[pos.level].buildings.transform);

            bi.Init(town, type, pos, cost ?? new Dictionary <string, int>(L.b.buildings[type].cost));
            bi.NextRound();
            GameMgmt.Get().data.buildings.Add(bi.data);
            buildings.Add(bi);
            return(bi);
        }
예제 #22
0
파일: Town.cs 프로젝트: TrutzX/9Nations
        public (int maxInhabitants, int buildingWorker) MaxInhabitantsAndWorker()
        {
            int maxInhabitants = 0;
            int buildWorker    = 0;

            //calculate inhabitants
            foreach (BuildingInfo buildingInfo in GameMgmt.Get().building.GetByTown(id))
            {
                if (buildingInfo.IsUnderConstruction())
                {
                    continue;
                }

                int w = buildingInfo.dataBuilding.worker;
                if (w > 0)
                {
                    maxInhabitants += w;
                }
                else
                {
                    buildWorker -= w;
                }
            }

            return(maxInhabitants, buildWorker);
        }
예제 #23
0
        protected override NVector CreateNewSpot()
        {
            int              level = Math.Max(GameMgmt.Get().data.map.standard - 1, 0); //underground
            GameMapData      gmap  = GameMgmt.Get().data.map;
            GameMapDataLevel gmdl  = GameMgmt.Get().data.map.levels[level];

            int i = 0;

            while (i < 1000)
            {
                i++;
                int         x = Random.Range(0, gmap.width);
                int         y = Random.Range(0, gmap.height);
                DataTerrain t = gmdl.Terrain(x, y);


                if (t.MoveCost("float") == 0 || t.MoveCost("float") > 10)
                {
                    continue;                                                       // can walk?
                }
                if (!S.Unit().Free(new NVector(x, y, gmap.standard)))
                {
                    continue;                                                 //near water?
                }
                return(new NVector(x, y, level));
            }

            Debug.Log($"{level}/{gmap.levels.Count}");

            NVector pos = new NVector(Random.Range(0, gmap.width), Random.Range(0, gmap.height), gmap.standard);

            Debug.LogError($"Can not find a start position using {pos}");
            return(pos);
        }
예제 #24
0
 private void ShowHideUnits()
 {
     //hide / show all objects
     foreach (UnitInfo u in GameMgmt.Get().unit.GetAll())
     {
         u.gameObject.SetActive(Visible(u.Pos()));
     }
 }
예제 #25
0
파일: Scenario.cs 프로젝트: TrutzX/9Nations
 public void Start()
 {
     GameMgmt.startConfig             = new Dictionary <string, string>();
     GameMgmt.startConfig["type"]     = "scenario";
     GameMgmt.startConfig["scenario"] = id;
     GameMgmt.startConfig["name"]     = Name() + " scenario";
     GameMgmt.Init();
 }
예제 #26
0
        private UnitInfo Unit(int pid, string id, NVector pos)
        {
            GameMgmt.Get().newMap.levels[pos.level].SetTile(new Vector3Int(pos.x, pos.y, 1), null);
            var b = S.Unit().Create(pid, id, pos);

            b.FinishConstruct();
            return(b);
        }
예제 #27
0
 private void ShowHideBuilding()
 {
     //hide / show all objects
     foreach (BuildingInfo b in GameMgmt.Get().building.GetAll())
     {
         b.gameObject.SetActive(Visible(b.Pos()));
     }
 }
예제 #28
0
 void Start()
 {
     S        = this;
     level    = 0;
     levelMax = collectibles.Length;
     StartLevel();
     uitWinText.text = "";
 }
예제 #29
0
 public void Init()
 {
     _activeLevel = GameMgmt.Get().data.map.standard;
     //which is the standard layer?
     for (int i = 0; i < _map.levels.Count; i++)
     {
         _map[i].gameObject.SetActive(_activeLevel == i);
     }
 }
예제 #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pos"></param>
        /// <returns>Improvement or null</returns>
        public Improvement At(NVector pos)
        {
            if (GameMgmt.Get().data.map.levels[pos.level].improvement[pos.x, pos.y] == null)
            {
                return(null);
            }

            return(data[GameMgmt.Get().data.map.levels[pos.level].improvement[pos.x, pos.y]]);
        }