Exemplo n.º 1
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);
            }
        }
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);
            }
        }