Exemplo n.º 1
0
        public static GameItem SpawnItem(string itemName, Vector3Int pos, Player owner)
        {
            if (owner == null)
            {
                owner = PlayersManager.Empty;
            }
            GameEntity ent   = null;
            var        chunk = ChunkManager.CurrentChunk;

            if (ChunkUtil.IsAnyEntity(chunk.ChunkNumber, pos))
            {
                ent = chunk.GetGameObjectByIndex(pos);
            }

            if (!SecondaryGroundLvL.IsEmptyPos(chunk.ChunkNumber, pos))
            {
                SecondaryGroundLvL.GetGroundEnt(chunk.ChunkNumber, pos).KillSelf();
            }

            var item = chunk.SetupItem(itemName, pos, owner);

            SecondaryGroundLvL.SetGroundEnt(chunk.ChunkNumber, pos, item);

            chunk.SetIndex(pos, -1);
            chunk.SetObjectAtPos(pos, null);

            if (ent != null)
            {
                chunk.SetIndex(pos, ent.PrefabIndex);
                chunk.SetObjectAtPos(pos, ent);
            }

            return(item);
        }
Exemplo n.º 2
0
        public static void Update(AbstractGameObject unit)
        {
            var EvolutionTime = unit.EvolutionTime;

            if (unit.State != EventManager.InProgressEvents.Stay)
            {
                ProgressUnitBar.RemoveProgressBar(unit);


                if (stackTarget.ContainsKey(unit))
                {
                    var target       = stackTarget[unit];
                    var progressName = ProgressUnitBar.ProgressName.GroupEvolution;
                    ProgressUnitBar.RemoveProgressBar(target, progressName);
                    stackTarget.Remove(unit);
                    stackTarget.Remove(target);
                }

                return;
            }

            var chunk = ChunkManager.GetChunkByNum(unit.ChunkNumber);

            //Solo evolution
            if (unit.SoloEvolution)
            {
                var progressName = ProgressUnitBar.ProgressName.SoloEvolution;
                var pos          = unit.CurrentPos;
                if (!SecondaryGroundLvL.IsEmptyPos(chunk.ChunkNumber, pos) &&
                    ChunkUtil.IsAnyEntity(chunk.ChunkNumber, pos))
                {
                    ProgressUnitBar.RemoveProgressBar(unit, progressName);
                    return;
                }

                ProgressUnitBar.Setup(unit, progressName, EvolutionTime);


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

                // Debug.Log("Original name = " + unit.OriginalName);


                if (SoloEvolutionDict.ContainsKey(unit.OriginalName) || unit.EvolutionNext.Length > 0)
                {
                    var evoName = "";
                    evoName = unit.EvolutionNext.Length == 0
                        ? SoloEvolutionDict[unit.OriginalName]
                        : unit.EvolutionNext;

                    if (evoName.Length > 0)
                    {
                        //  Debug.Log("Evolution name = " + evoName);

                        var prevIndex = ChunkUtil.GetIndex(chunk.ChunkNumber, pos);
                        var prevEnt   = chunk.GetGameObjectByIndex(pos);
                        var check     = unit.PrefabIndex == prevIndex;


                        unit.KillSelf();

                        if (!SecondaryGroundLvL.IsEmptyPos(chunk.ChunkNumber, pos))
                        {
                            SecondaryGroundLvL.GetGroundEnt(chunk.ChunkNumber, pos).KillSelf();
                            SecondaryGroundLvL.RemovePos(chunk.ChunkNumber, pos);
                        }

                        var ent = chunk.PreSetupObject(evoName, pos, unit.Owner);

                        if (GroupUtil.isBuilding(ent.Group) || GroupUtil.IsItem(ent.Group))
                        {
                            chunk.SetupItem(ent, evoName, pos, unit.Owner);
                        }
                        else
                        {
                            chunk.SetupUnit(ent, evoName, pos, unit.Owner);
                        }
                    }
                }
            }
            //Group evolution
            else if (stackResult.ContainsKey(unit.OriginalName))
            {
                var progressName = ProgressUnitBar.ProgressName.GroupEvolution;
                var friends      = AI_Calculation.GetNearFriendUnits(chunk.ChunkNumber, unit, unit.CurrentPos);


                GameEntity target = null;
                if (stackTarget.ContainsKey(unit))
                {
                    target = stackTarget[unit];
                }

                if (target != null && !friends.Contains(target as GameUnit))
                {
                    ProgressUnitBar.RemoveProgressBar(target, progressName);
                    target = null;
                    stackTarget.Remove(unit);
                }
                foreach (var obj in friends)
                {
                    if (obj.Destroyed)
                    {
                        continue;
                    }
                    if (!stackResult[unit.OriginalName].ContainsKey(obj.OriginalName))
                    {
                        continue;
                    }
                    if (obj.State != EventManager.InProgressEvents.Stay)
                    {
                        continue;
                    }

                    stackTarget[unit] = obj;
                    target            = obj;
                    break;
                }

                if (target == null)
                {
                    return;
                }

                ProgressUnitBar.Setup(unit, progressName, EvolutionTime);

                //EvolutionTimeList[target] = EvolutionTimeList[ent];
                // UpdateProgressBar(target);

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

                var evoName = stackResult[unit.OriginalName][target.OriginalName];
                var pos     = unit.CurrentPos;
                var owner   = unit.Owner;

                unit.KillSelf();
                target.KillSelf();

                var evoUnit = chunk.SetupUnit(evoName, pos, owner);
                QuestManager.OnEvolution(evoUnit);

                Coloring.RecolorObject(ChunkUtil.GetDovvner(unit.CurrentPos));
                Coloring.RecolorObject(ChunkUtil.GetDovvner(target.CurrentPos));

                UnitEvents.OnEvolution(evoUnit);

                PathCalcManager.CalculatePoint(ChunkUtil.GetDovvner(pos));
                PathCalcManager.CalculatePoint(pos);
            }
        }