Exemple #1
0
        public override void KillSelf()
        {
            if (Destroyed)
            {
                return;
            }


            if (SecondaryGroundLvL.isSecondaryGroup(Group))
            {
                SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos);
            }
            else
            {
                var chunk = ChunkManager.GetChunkByNum(ChunkNumber);
                chunk.SetIndex(CurrentPos, -1);
                chunk.RemoveObject(CurrentPos);
            }

            ProgressUnitBar.RemoveProgressBar(this);



            if (gameObject != null)
            {
                ClickManager.RemoveChosing(gameObject);
                Destroy(gameObject);
            }
            Destroyed = true;
        }
Exemple #2
0
        public static void OnFogChange()
        {
            if (!ChunkManager.staticFogEnabled || ChunkManager.CurrentChunk == null)
            {
                return;
            }
            var ents = ChunkManager.CurrentChunk.Ground;

            for (int x = 0; x < ents[0].Length; x++)
            {
                for (int y = 0; y < ents[0][0].Length; y++)
                {
                    var ent  = ents[0][x][y];
                    var item = SecondaryGroundLvL.GetGroundEnt(ChunkManager.CurrentChunk.ChunkNumber,
                                                               new Vector3Int(x, y, 1));
                    if (item != null)
                    {
                        Coloring.RecolorObject(item, true);
                        Coloring.RecolorObject(new Vector3Int(x, y, 0), true);
                    }
                    else if (ent != null)
                    {
                        OnGroundEntity(ent);
                    }
                }
            }
        }
Exemple #3
0
        public virtual void KillSelf()
        {
            if (Destroyed)
            {
                return;
            }
            var chunk = ChunkManager.GetChunkByNum(ChunkNumber);


            chunk.SetIndex(CurrentPos, -1);
            chunk.RemoveObject(CurrentPos);


            var ent = chunk.GetGameObjectByIndex(ChunkUtil.GetDovvner(CurrentPos));

            if (ent != null)
            {
                Coloring.RecolorObject(ent.CurrentPos);
            }


            Destroy(gameObject);

            if (SecondaryGroundLvL.isSecondaryGroup(Group))
            {
                SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos);
            }


            Destroyed = true;
        }
Exemple #4
0
        public void ClearChunk()
        {
            for (var z = 0; z < ChunkManager.MaxGroundsLvls; z++)
            {
                for (var x = 0; x < MapSize; x++)
                {
                    for (var y = 0; y < MapSize; y++)
                    {
                        var obj = Ground[z][x][y];
                        if (obj == null)
                        {
                            continue;
                        }

                        if (obj is GameUnit)
                        {
                            var unit = obj as GameUnit;
                            unit.Disable();
                            IndexMas[z][x][y] = 0;
                            Ground[z][x][y]   = null;
                        }
                        else
                        {
                            var index = obj.PrefabIndex;
                            obj.KillSelf();
                            IndexMas[z][x][y] = index;
                        }
                    }
                }
            }
            SecondaryGroundLvL.RemoveChunk(ChunkNumber);
        }
Exemple #5
0
        public void FullRemove()
        {
            for (var z = 0; z < ChunkManager.MaxGroundsLvls; z++)
            {
                for (var x = 0; x < MapSize; x++)
                {
                    for (var y = 0; y < MapSize; y++)
                    {
                        var pos = new Vector3Int(x, y, z);
                        if (!SecondaryGroundLvL.IsEmptyPos(ChunkNumber, pos))
                        {
                            SecondaryGroundLvL.GetGroundEnt(ChunkNumber, pos).KillSelf();
                        }


                        IndexMas[z][x][y] = 0;
                        var obj = Ground[z][x][y];
                        if (obj == null)
                        {
                            continue;
                        }
                        obj.KillSelf();
                    }
                }
            }
            SecondaryGroundLvL.FullRemoveChunk(ChunkNumber);
        }
Exemple #6
0
        public virtual bool IsTimeForReproduction(GameUnit unit)
        {
            var lairPos = ChunkUtil.GetUpper(unit.GroupObj.GetLairPos());

            return(IsSetUpedLairPos(unit) &&
                   !SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, lairPos) &&
                   SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, lairPos).OriginalName == "building_lair");
        }
Exemple #7
0
        public GameItem SetupItem(GameEntity ent, string name, Vector3Int pos, Player owner)
        {
            var index = Loader.GetIndexByName(name);
            var npc   = LuaNpcGetter.GetNpcById(index);

            ent.Owner        = owner;
            ent.OriginalName = name;
            ent.name         = name;
            var item = ent as GameItem;

            var evoTo = LuaNpcGetter.GetEvolutionTo(npc);

            if (evoTo.Length > 0)
            {
                if (!UnitEvolution.IsHasSoloEvolution(name))
                {
                    UnitEvolution.AddToSoloDict(name, evoTo);
                }

                if (item != null)
                {
                    item.SoloEvolution = true;
                }
            }

            var evoCross = LuaNpcGetter.GetNpcEvoCrossing(npc);

            if (evoCross.Keys.Count > 0)
            {
                foreach (var pair in evoCross)
                {
                    UnitEvolution.AddToStackDict(name, pair.Key, pair.Value);

                    if (!string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase))
                    {
                        UnitEvolution.AddToStackDict(pair.Key, name, pair.Value);
                    }
                }
            }
            if (GroupUtil.IsItem(ent.Group))
            {
                SecondaryGroundLvL.SetGroundEnt(ChunkNumber, pos, item);
            }

            if (GroupUtil.isBuilding(ent.Group))
            {
                ChunkManager.AddVision(ent);
            }
            ItemEvents.OnCreateItem(item, firstCreate);

            Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos));

            return(item);
        }
Exemple #8
0
        public virtual bool IsTimeForDeliverItem(GameUnit unit)
        {
            var lairPos = ChunkUtil.GetUpper(unit.GroupObj.GetLairPos());

            if (unit.pickUped == null || !unit.GroupObj.IsSetUpedLairPos(unit) ||
                (ChunkUtil.IsAnyEntity(unit.ChunkNumber, lairPos) && unit.CurrentPos != lairPos))
            {
                return(false);
            }
            if (!SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, lairPos))
            {
                return(ItemGroup.IsCanBeStacked(unit.pickUped.OriginalName,
                                                SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, lairPos).OriginalName));
            }
            return(true);
        }
Exemple #9
0
        public virtual bool IsTimeForPickupItem(GameUnit unit)
        {
            if (SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, unit.CurrentPos))
            {
                return(false);
            }
            var item = SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, unit.CurrentPos);

            return(item != null &&
                   item.CanBePickuped &&
                   !item.SoloEvolution &&
                   item.Group == "item" &&
                   unit.pickUped == null &&
                   TreeGroup.IsPickableTreeLog(item) &&
                   unit.GroupObj.GetLairPos() != ChunkUtil.GetDovvner(unit.CurrentPos));
        }
Exemple #10
0
        public static Vector3Int FindFreePosNearPos(int chunkNumber, Vector3Int pos, bool includeSecondLvl)
        {
            for (var i = 1; i < 100; i++)
            {
                var neighbourPoints = new Vector3Int[8];
                neighbourPoints[0] = new Vector3Int(pos.x + i, pos.y, pos.z);
                neighbourPoints[1] = new Vector3Int(pos.x - i, pos.y, pos.z);
                neighbourPoints[2] = new Vector3Int(pos.x, pos.y + i, pos.z);
                neighbourPoints[3] = new Vector3Int(pos.x, pos.y - i, pos.z);

                neighbourPoints[4] = new Vector3Int(pos.x + i, pos.y + i, pos.z);
                neighbourPoints[5] = new Vector3Int(pos.x - i, pos.y - i, pos.z);
                neighbourPoints[6] = new Vector3Int(pos.x - i, pos.y + i, pos.z);
                neighbourPoints[7] = new Vector3Int(pos.x + i, pos.y - i, pos.z);

                var chunk = ChunkManager.GetChunkByNum(chunkNumber);
                foreach (var point in neighbourPoints)
                {
                    if (chunk.IsMapPos(point) && !IsInvalidPoint(chunkNumber, point))
                    {
                        if (includeSecondLvl)
                        {
                            if (SecondaryGroundLvL.IsEmptyPos(chunkNumber, point))
                            {
                                return(point);
                            }
                        }
                        else
                        {
                            return(point);
                        }
                    }
                }
            }
            return(Vector3Int.zero);
        }
Exemple #11
0
        public static void Update(GameUnit unit)
        {
            if (unit.State != EventManager.InProgressEvents.Stay)
            {
                ProgressUnitBar.RemoveProgressBar(unit);
                unit.StayOnBuilding = false;
                return;
            }


            //Dropping at ground
            if (unit.pickUped != null)
            {
                //if item on ground and not stacking return
                if (!SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, unit.CurrentPos))
                {
                    var gEntName = SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, unit.CurrentPos).OriginalName;
                    if (ItemGroup.GetStackResult(unit.pickUped.OriginalName, gEntName).Length == 0)
                    {
                        return;
                    }
                }


                //Item on ground
                if (!SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, unit.CurrentPos))
                {
                    var progressName = ProgressUnitBar.ProgressName.Stucking;

                    ProgressUnitBar.Setup(unit, progressName, NeedToPickupTime);
                    //Time to pickup
                    if (!ProgressUnitBar.IsReady(unit) ||
                        !ProgressUnitBar.IsThisProgressName(unit, progressName))
                    {
                        return;
                    }


                    var onGround = SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, unit.CurrentPos);
                    var stack    = ItemGroup.GetStackResult(unit.pickUped.OriginalName, onGround.OriginalName);
                    if (stack.Length > 0)
                    {
                        var item = SpecialActions.SpawnItem(stack, unit.CurrentPos, unit.Owner);

                        ItemEvents.OnDropItem(unit.pickUped, unit);

                        unit.pickUped.KillSelf();
                        onGround.KillSelf();

                        unit.pickUped = null;
                        SecondaryGroundLvL.SetGroundEnt(unit.ChunkNumber, unit.CurrentPos, item);

                        QuestManager.OnItemStuck(item);

                        var chunk = ChunkManager.GetChunkByNum(unit.ChunkNumber);
                        chunk.SetIndex(unit.CurrentPos, unit.PrefabIndex);
                        chunk.SetObjectAtPos(unit.CurrentPos, unit);
                    }
                }
                //Ground empty
                else
                {
                    var progressName = ProgressUnitBar.ProgressName.Dropping;
                    ProgressUnitBar.Setup(unit, progressName, NeedToPickupTime);
                    //Time to pickup
                    if (!ProgressUnitBar.IsReady(unit) ||
                        !ProgressUnitBar.IsThisProgressName(unit, progressName))
                    {
                        return;
                    }

                    var prev3DPos = Util.Get3DPosByIndex(unit.pickUped.CurrentPos);


                    var pos = unit.pickUped.transform.position - prev3DPos;
                    pos.z = 0;

                    var d = unit.CurrentPos;
                    var get3DPosByIndex = Util.Get3DPosByIndex(d);
                    get3DPosByIndex.z -= d.z / 150f;


                    unit.pickUped.CurrentPos         = unit.CurrentPos;
                    unit.pickUped.transform.position = get3DPosByIndex + pos;

                    unit.pickUped.transform.Translate(0, 0, 0.01f);

                    var rend = unit.pickUped.GetComponent <SpriteRenderer>();
                    rend.enabled = true;


                    SecondaryGroundLvL.SetGroundEnt(unit.ChunkNumber, unit.CurrentPos, unit.pickUped);

                    ItemEvents.OnDropItem(unit.pickUped, unit);

                    unit.pickUped = null;
                }

                ProgressUnitBar.RemoveProgressBar(unit);
            }
            //Pickuping from ground
            else if (
                unit.StayOnBuilding || !SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, unit.CurrentPos))
            {
                var progressName = ProgressUnitBar.ProgressName.Pickuping;
                var item         = SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, unit.CurrentPos);
                var objGroup     = item.Group;
                if (objGroup.ToLower() != "item")
                {
                    return;
                }
                if (item.SoloEvolution)
                {
                    return;
                }

                unit.StayOnBuilding = true;


                ProgressUnitBar.Setup(unit, progressName, NeedToPickupTime);

                if (!ProgressUnitBar.IsReady(unit) ||
                    !ProgressUnitBar.IsThisProgressName(unit, progressName))
                {
                    return;
                }

                unit.StayOnBuilding = false;
                ProgressUnitBar.RemoveProgressBar(unit, progressName);

                if (item.Destroyed)
                {
                    return;
                }
                var rend = item.GetComponent <SpriteRenderer>();
                rend.enabled = false;

                unit.pickUped = item;
                ItemEvents.OnPickup(unit.pickUped, unit);

                SecondaryGroundLvL.RemovePos(unit.ChunkNumber, unit.CurrentPos);
            }
        }
Exemple #12
0
        public static void RecolorObject(GameEntity ent, bool trueCall)
        {
            if (ent == null || ((Recolor.IsHided(ent) && !trueCall) && ChunkManager.staticFogEnabled))
            {
                return;
            }


            var mod   = 3f;
            var upper = ChunkUtil.GetUpper(ent.CurrentPos);

            if ((ChunkUtil.IsAnyEntity(ent.ChunkNumber, upper) ||
                 !SecondaryGroundLvL.IsEmptyPos(ent.ChunkNumber, upper)) &&
                ent.CurrentPos.z + 1 != ChunkManager.MaxGroundsLvls)
            {
                mod += 2.5f;
            }


            var i     = 1f / ((ent.CurrentPos.z + mod) * 0.3f);
            var color = new Color(i, i, i);

            if (ChunkUtil.IsEntity(ent.ChunkNumber, upper) &&
                ent.CurrentPos.z + 1 != ChunkManager.MaxGroundsLvls)
            {
                var chunk    = ChunkManager.GetChunkByNum(ent.ChunkNumber);
                var upperEnt = chunk.GetGameObjectByIndex(upper);
                if (upperEnt != null)
                {
                    if (TreeGroup.IsTreeGroup(upperEnt.Group))
                    {
                        color.r = 0.5f;
                        color.b = 0.7f;
                        color.g = 0.3f;
                    }
                    else if (upperEnt.Group == "rock")
                    {
                        color.r = 0.3f;
                        color.b = 0.7f;
                        color.g = 0.2f;
                    }
                    else if (upperEnt is GameUnit)
                    {
                        var unit = upperEnt as GameUnit;
                        if (unit.IsEnemy(PlayersManager.GetMyPlayer()))
                        {
                            color.r = 1;
                            color.b = 0.3f;
                            color.g = 0.3f;
                        }
                        else
                        {
                            color.r = 0.1f;
                            color.b = 0.1f;
                            color.g = 0.6f;
                        }
                    }
                    else
                    {
                        color.r = 0.1f;
                        color.b = 0.1f;
                        color.g = 0.6f;
                    }
                }
            }

            if (!GroupUtil.isCreatureGroup(ent.Group) &&
                !GroupUtil.isBuilding(ent.Group))
            {
                var spriteRenderer = ent.GetComponent <SpriteRenderer>();
                spriteRenderer.color = color;
            }
        }
Exemple #13
0
        void RghtClickedOnGameObject(GameObject obj)
        {
            if (_choosed)
            {
                var from = _choosedObj.GetComponent <GameUnit>();
                if (from == null || !from.IsMy())
                {
                    return;
                }
                var to = obj.GetComponent <GameEntity>();

                if (to == null)
                {
                    return;
                }

                if (!GroupUtil.isCreatureGroup(from.Group))
                {
                    return;
                }


                if (!FieldOfView.IsVisible(to) && !GroupUtil.IsGround(to.Group))
                {
                    ClickedOnSpace();
                    return;
                }

                Vector3Int f;
                if (from.MovingTo != null)
                {
                    f = from.MovingTo.Index;
                }
                else
                {
                    f = from.CurrentPos;
                    f.z--;
                }

                //Cant move ?
                if (from.UpgradedStats.MoveSpeed <= 0f)
                {
                    SimpleOrderManager.CancelOrders(from);
                    ErrorBar_HTML.SetupError("This unit can`t move!");
                    return;
                }

                //Attack
                var t             = to.CurrentPos;
                var buildingCheck = false;
                if (ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(t)))
                {
                    var underGround = ChunkManager.CurrentChunk.GetGameObjectByIndex(ChunkUtil.GetUpper(t));
                    var underEnt    = underGround.GetComponent <GameEntity>();
                    if (SecondaryGroundLvL.isSecondaryGroup(underEnt.Group))
                    {
                        buildingCheck = true;
                    }

                    if (!GroupUtil.IsGround(underEnt.Group) && underEnt.Owner != PlayersManager.GetMyPlayer())
                    {
                        var underP = underEnt.CurrentPos;
                        underP.z++;

                        if (!ChunkManager.CurrentChunk.IsMapPos(underP) ||
                            !ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(underEnt.CurrentPos)))
                        {
                            if (from.UpgradedStats.Dmg > 0)
                            {
                                SimpleOrderManager.AttackToIndex(from, t);
                            }
                            else if (from.UpgradedStats.Dmg == 0)
                            {
                                ErrorBar_HTML.SetupError("This unit can`t attack!");
                            }
                            return;
                        }
                    }
                }


                //Cancel or Move
                if ((ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(t)) ||
                     !PathCalcManager.IsReaching(f, t)) && !buildingCheck)
                {
                    ErrorBar_HTML.SetupError("Can`t reach that place!");
                    SimpleOrderManager.CancelOrders(from);
                }
                else if (ChunkUtil.IsCanStayHere(from.ChunkNumber, t) || buildingCheck)
                {
                    SimpleOrderManager.MoveToIndex(from, t);
                }
            }
            else
            {
                var clicked = obj.GetComponent <GameEntity>();
                if (clicked == null)
                {
                    return;
                }

                var pos = clicked.CurrentPos;

                if (FlagManager.IsFlagAtPos(pos))
                {
                    FlagManager.RemoveFlag(pos);
                }
                else
                {
                    FlagManager.SetupFlag(pos);
                }
            }
        }
Exemple #14
0
        public override void KillSelf()
        {
            if (Destroyed)
            {
                return;
            }
            var chunk = ChunkManager.GetChunkByNum(ChunkNumber);

            chunk.SetIndex(CurrentPos, -1);
            chunk.RemoveObject(CurrentPos);

            if (pickUped != null)
            {
                ItemEvents.OnDeathDropItem(pickUped, this);
            }

            ClickManager.RemoveChosing(gameObject);

            GameMoveManager.CancelAllOrders(this);
            if (GroupUtil.isCreatureGroup(Group))
            {
                GameOrderManager.RemoveMarks(this);
                //SimpleOrderManager.CancelOrders(this);
                if (MovingPath != null)
                {
                    MovingPath.Clear();
                }
            }

            if (SecondaryGroundLvL.isSecondaryGroup(Group))
            {
                SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos);
            }

            if (FlagManager.IsFlagAtPos(CurrentPos))
            {
                FlagManager.RemoveFlag(CurrentPos);
            }

            ProgressUnitBar.RemoveProgressBar(this);
            CreatureGroupManager.RemoveEntFromGroup(this);
            BuildingsGroupManager.RemoveBuildingFromGroup(this);

            RemoveAbilities();

            if (research != null)
            {
                var sameBuilds = BuildingsGroupManager.GetAllInChunkWithName(ChunkNumber, OriginalName);
                if (sameBuilds.Count == 0)
                {
                    Owner.RemoveResearch(research);
                }
            }
            Coloring.RecolorObject(ChunkUtil.GetDovvner(CurrentPos));
            Owner.foodCount -= foodCost;
            Owner.foodMax   -= foodGive;

            if (gameObject != null)
            {
                Destroy(gameObject);
            }


            Destroyed = true;
        }