Ejemplo n.º 1
0
        void GetPlayers(User user)
        {
            for (int i = 0; i < user.Count; i++)
            {
                Player player = ComponentFactory.CreateWithId <Player>(IdGenerater.GenerateId());
                player.UserId        = user.Id;
                player.Account       = user.Account;
                player.spawnPosition = new Vector3(-40, 0, -20);

                player.AddComponent <NumericComponent>();

                NumericComponent numC = player.GetComponent <NumericComponent>();
                ///20190621
                // 这里初始化base值,给各个数值进行赋值
                // 注意,这两个语句都将触发数值改变组件,只是没有写Max的处理函数,所以会没有反应
                player.GetComponent <NumericComponent>().Set(NumericType.ValuationBase, 40);
                player.GetComponent <NumericComponent>().Set(NumericType.MaxValuationBase, 120);
                //player.GetComponent<NumericComponent>().Set(NumericType.ManageBase, 10);
                //player.GetComponent<NumericComponent>().Set(NumericType.MaxManageBase, 40);
                player.GetComponent <NumericComponent>().Set(NumericType.CaseBase, 14);
                player.GetComponent <NumericComponent>().Set(NumericType.MaxCaseBase, 40);

                player.GetComponent <NumericComponent>().Set(NumericType.LevelBase, 1);
                player.GetComponent <NumericComponent>().Set(NumericType.ExpBase, 1);
                player.GetComponent <NumericComponent>().Set(NumericType.CoinBase, 1);

                player.GetComponent <NumericComponent>().Set(NumericType.ValuationAdd, 140);      // HpAdd 数值,进行赋值
                player.GetComponent <NumericComponent>().Set(NumericType.MaxValuationAdd, 140);   // MaxHpAdd 数值,进行赋值

                players.Add(player.Id, player);
            }
        }
Ejemplo n.º 2
0
        public void Awake()
        {
            Game.Scene.GetComponent <FUIPackageComponent>().AddPackage("OverHead");

            this.m_tank = this.GetParent <Tank>();

            this.m_overHeadGO = this.m_tank.GameObject.FindChildObjectByPath("OverHead");

            this.m_overHeadGO.SetActive(true);

            this.m_uiPanel = this.m_overHeadGO.GetComponent <UIPanel>();

            this.m_name = this.m_uiPanel.ui.GetChild("name").asRichTextField;

            this.m_redBar = this.m_uiPanel.ui.GetChild("n0").asProgress;

            this.m_whiteBar = this.m_uiPanel.ui.GetChild("n1").asProgress;

            this.m_name.text = this.m_tank.Name;

            m_numericComponent = this.m_tank.GetComponent <NumericComponent>();

            this.m_redBar.max = m_numericComponent[NumericType.MaxHp];

            this.m_redBar.value = m_numericComponent[NumericType.Hp];

            this.m_whiteBar.max = 100;

            this.m_whiteBar.value = 100;

            if (this.m_tank.TankCamp != TankComponent.Instance.MyTank.TankCamp)
            {
                this.m_name.color = Color.red;
            }
        }
Ejemplo n.º 3
0
        //public bool isShow = true;

        //public void Update()
        //{
        //    //RecoverHp();
        //}

        /// <summary>
        /// 更新 回复血量
        /// </summary>
        /// <param name="self"></param>
        public void RecoverHp()
        {
            NumericComponent numC = this.GetParent <Unit>().GetComponent <NumericComponent>();

            if (numC[NumericType.Valuation] == numC[NumericType.MaxValuation])
            {
                return;
            }

            if (numC[NumericType.Valuation] > numC[NumericType.MaxValuation])
            {
                numC[NumericType.Valuation] = numC[NumericType.MaxValuation];

                Console.WriteLine(" type/Hp/hb/ha: " + numC.GetParent <Unit>().UnitType + " :" + numC[NumericType.Valuation] + " / " + numC[NumericType.ValuationBase] + " / " + numC[NumericType.ValuationAdd]);

                return;
            }

            if (numC[NumericType.Valuation] < numC[NumericType.MaxValuation])
            {
                if (!this.hpNull)
                {
                    this.hptimer = TimeHelper.ClientNowSeconds();
                    this.hpNull  = true;
                }

                long timeNow = TimeHelper.ClientNowSeconds();

                if ((timeNow - this.hptimer) > this.reshpTime)
                {
                    numC[NumericType.ValuationAdd] += (int)(numC[NumericType.MaxValuation] * this.reshp);
                    this.hpNull = false;
                }
            }
        }
Ejemplo n.º 4
0
        public void Run(long id, int value)
        {
            ///20190621
            Unit unit = Game.Scene.GetComponent <MonsterUnitComponent>().Get(id);

            if (unit != null)
            {
                NumericComponent num = unit.GetComponent <NumericComponent>();
                int hb = num[NumericType.ValuationBase];
                int ha = num[NumericType.ValuationAdd];

                Console.WriteLine(" type/Hp/hb/ha: " + unit.UnitType + " :" + value + " / " + hb + " / " + ha);
            }
        }
Ejemplo n.º 5
0
        public void Run(long battleId, long tankId, NumericType changeType)
        {
            try
            {
                Tank tank = Game.Scene.GetComponent <BattleComponent>().Get(battleId).Get(tankId);
                if (tank == null)
                {
                    return;
                }

                NumericComponent numericComponent = tank.GetComponent <NumericComponent>();

                if (numericComponent == null)
                {
                    Log.Error($"未添加NumericComponent组件");
                    return;
                }

                int nowHp = numericComponent[NumericType.Hp];

                if (nowHp <= 0)
                {
                    tank.Died = true;



                    if (tank.Battle.BigMode == BigModel.Time)
                    {
                        tank.Battle.TimeResetTank(tank).NoAwait();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Ejemplo n.º 6
0
        //没法准确的在那一刻恢复,但是可以降低调用频率,尤其服务器,每个Update调用太耗了
        public void FixedUpdate()
        {
            if (TimeHelper.Now() - timer.timing >= timer.interval)
            {
                timer.timing += timer.interval;
                NumericComponent numericComponent = this.Entity.GetComponent <NumericComponent>();

                CharacterStateComponent unitStateComponent = this.Entity.GetComponent <CharacterStateComponent>();
                if (!unitStateComponent.Get(SpecialStateType.Die))
                {
                    return;
                }
                if (numericComponent.GetAsFloat(NumericType.HP_RemainPct) < 1.0f)
                {
                    if (unitStateComponent.Get(SpecialStateType.InBattle))
                    {
                        GetHP(numericComponent.GetAsInt(NumericType.HP_Restore));
                    }
                    else
                    {
                        GetHP(Mathf.RoundToInt(numericComponent.GetAsFloat(NumericType.HPMax_Final) * restorePct_NotInBattle));
                    }
                }
                if (numericComponent.GetAsFloat(NumericType.MP_RemainPct) < 1.0f)
                {
                    if (unitStateComponent.Get(SpecialStateType.InBattle))
                    {
                        GetMP(numericComponent.GetAsInt(NumericType.MP_Restore));
                    }
                    else
                    {
                        GetMP(Mathf.RoundToInt(numericComponent.GetAsFloat(NumericType.MPMax_Final) * restorePct_NotInBattle));
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static Tank Create(TankInfoFirstEnter firstInfo, Vector3 Pos, Vector3 Rot)
        {
            long id = firstInfo.TankFrameInfo.TankId;

            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            //Game.Scene.GetComponent<ResourcesComponent>().LoadBundle($"Unit.unity3d");
            GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(AssetBundleName.Unit, PrefabName.Unit);
            //Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle($"Unit.unity3d");
            GameObject prefab = bundleGameObject.Get <GameObject>(PrefabName.Tank);

            TankComponent tankComponent = Game.Scene.GetComponent <TankComponent>();

            Tank tank = ComponentFactory.CreateWithId <Tank>(id);

            tank.GameObject = resourcesComponent.NewObj(PrefabType.Tank, prefab);

            tank.GameObject.transform.position = Pos;

            tank.GameObject.transform.eulerAngles = Rot;


            GameObject parent = GameObject.Find($"/Global/Unit");

            tank.GameObject.transform.SetParent(parent.transform, false);

            NumericComponent numericComponent = tank.AddComponent <NumericComponent>();

            tank.Name = firstInfo.Name;

            tank.TankCamp = firstInfo.TankCamp;

            if (id == 10000 || PlayerComponent.Instance.MyPlayer.TankId == id)
            {
                tank.TankType = TankType.Local;

                tank.AddComponent <TankMoveComponent>();

                tank.AddComponent <CameraComponent>();

                tank.AddComponent <TurretComponent>();

                // 子弹管理组件
                tank.AddComponent <BulletComponent>();

                // 发射子弹的组件
                tank.AddComponent <TankShootComponent>();

                tank.AddComponent <LocalTankComponent>();

                tankComponent.MyTank = tank;

                // 如果是自己设置层级为9,为了让坦克不打中自己

                Utility.ChangeLayer(tank.GameObject, LayerNames.OwnTank);

                tank.GameObject.layer = 9;
            }
            else
            {
                tank.TankType = TankType.Remote;

                tank.AddComponent <RemoteTankComponent>();

                tank.AddComponent <TurretComponent>();

                tank.AddComponent <TankShootComponent>();

                tank.AddComponent <BulletComponent>();

                tank.AddComponent <OverHeadComponent>();
            }



            tankComponent.Add(tank);

            // 先将坦克加入TankComponent再赋值,因为赋值的时候会触发事件,事件中可能要从TankComponent中取坦克
            numericComponent[NumericType.MaxHpBase] = firstInfo.MaxHpBase;

            numericComponent[NumericType.HpBase] = firstInfo.HpBase;

            numericComponent[NumericType.AtkBase] = firstInfo.AtkBase;

            return(tank);
        }
        public override void Run(NumericType nt, long destUnitId, float updateValue)
        {
#if !SERVER
            if (GlobalConfigComponent.Instance.networkPlayMode)
            {
                return;
            }
#endif
            Unit             unit             = UnitComponent.Instance.Get(destUnitId);
            NumericComponent numericComponent = unit.GetComponent <NumericComponent>();

            CharacterStateComponent unitStateComponent = unit.GetComponent <CharacterStateComponent>();
            if (!unitStateComponent.Get(SpecialStateType.Die))
            {
                return;  //角色已经死亡,不再受到任何属性影响
            }
            switch (nt)
            {
            case NumericType.HP:

                int value    = numericComponent.GetAsInt(NumericType.HP) + Mathf.RoundToInt(updateValue);
                int maxValue = numericComponent.GetAsInt(NumericType.HPMax_Final);
                value = Mathf.Clamp(value, 0, maxValue);
                numericComponent.Set(NumericType.HP, value);
                Game.EventSystem.Run(EventIdType.HPChanged, destUnitId);
                if (value == 0)
                {
                    Game.EventSystem.Run(EventIdType.OnUnitDie, destUnitId);
                }
                break;

            case NumericType.MP:
                value    = numericComponent.GetAsInt(NumericType.MP) + Mathf.RoundToInt(updateValue);
                maxValue = numericComponent.GetAsInt(NumericType.MPMax_Final);
                value    = Mathf.Clamp(value, 0, maxValue);
                numericComponent.Set(NumericType.MP, value);
                Game.EventSystem.Run(EventIdType.MPChanged, destUnitId);
                break;

            //case NumericType.HPMax_Pct:
            //case NumericType.HP_LeechRate:
            //case NumericType.MPMax_Pct:
            //case NumericType.MP_LeechRate:
            //case NumericType.HitRate:
            //case NumericType.CritDamagePct:
            //case NumericType.CritRate:
            //case NumericType.DodgeRate:
            //case NumericType.FinalDamage_AddPct:
            //case NumericType.FinalDamage_ReducePct:
            //    //这些全都是百分比的值(float)
            //    float fvalue = numericComponent.GetAsFloat(nt) + updateValue;
            //    numericComponent.Set(nt, fvalue);
            //break;
            case NumericType.HP_LosePct:
            case NumericType.HP_RemainPct:
            case NumericType.MP_LosePct:
            case NumericType.MP_RemainPct:
            case NumericType.HP_LoseValue:
            case NumericType.MP_LoseValue:
                Log.Error("这些属性不应该被直接改变,它们是间接被改变的值");
                break;

            default:
                float fvalue = numericComponent.GetAsFloat(nt) + updateValue;
                numericComponent.Set(nt, fvalue);
                break;
            }
        }