예제 #1
0
    public MonsterData(int entityId, int typeId, CampType camp, int prize) : base(entityId, typeId, camp)
    {
        IDataTable <DRMonster> dtMonster = GameEntry.DataTable.GetDataTable <DRMonster> ();
        DRMonster drMonster = dtMonster.GetDataRow(typeId);

        if (drMonster == null)
        {
            return;
        }

        Name        = drMonster.Name;
        HP          = drMonster.HP;
        MaxHP       = HP;
        MoveSpeed   = drMonster.MoveSpeed;
        RotateSpeed = drMonster.RotateSpeed;
        Atk         = drMonster.Atk;
        AtkAnimTime = drMonster.AtkAnimTime;
        AtkRange    = drMonster.AtkRange;
        SeekRange   = drMonster.SeekRange;
        Def         = drMonster.Def;
        AtkSpeed    = drMonster.AtkSpeed;

        this.Prize = prize;

        for (int i = 0; i < drMonster.GetWeaponCount(); i++)
        {
            weaponDatas.Add(new WeaponData(EntityExtension.GenerateSerialId(), drMonster.GetWeaponID(i), Id, Camp));
        }
    }
    /// <summary>
    /// 根据玩家角色拥有的武器,初始化操作按钮
    /// </summary>
    private void InitWeaponButtons()
    {
        HeroData          heroData    = new HeroData(EntityExtension.GenerateSerialId(), PlayerData.CurrentFightHeroID, CampType.Player);
        List <WeaponData> weaponDatas = heroData.GetWeaponDatas();

        for (int i = 0; i < weaponDatas.Count; i++)
        {
            WeaponData weaponData = weaponDatas[i];
            string     buttonText = $"{weaponData.Name}({weaponData.CostMP}MP)";

            switch (weaponDatas[i].AttackType)
            {
            case WeaponAttackType.手动触发:
                CreateButton(attackButtonParent, buttonText, OnAtkClick);
                break;

            case WeaponAttackType.自动触发:
                break;

            case WeaponAttackType.技能触发:
                CreateButton(skillButtonParent, buttonText, () => {
                    OnSkillClick(weaponData);
                });
                break;
            }
        }
    }
예제 #3
0
    /// <summary>
    /// 创建生物
    /// </summary>
    public void CreateCreatures()
    {
        // 创建主角
        HeroData heroData = new HeroData(EntityExtension.GenerateSerialId(), PlayerData.CurrentFightHeroID, CampType.Player);

        heroData.Position = new Vector3(15, 0, 15);
        EntityExtension.ShowHero(typeof(Hero), "PlayerGroup", heroData);

        // 创建魔力泉
        IDataTable <DRMagicWater> dtMagicWater = GameEntry.DataTable.GetDataTable <DRMagicWater> ();

        DRMagicWater[] magicWaters = dtMagicWater.GetAllDataRows();

        foreach (DRMagicWater magicWater in magicWaters)
        {
            MagicWaterData magicWaterData = new MagicWaterData(EntityExtension.GenerateSerialId(), magicWater.Id);
            EntityExtension.ShowMagicWater(typeof(MagicWater), "MagicWaterGroup", magicWaterData);
        }

        // 创建怪物生成器
        IDataTable <DRMonsterCreater> dtMonsterCreater = GameEntry.DataTable.GetDataTable <DRMonsterCreater> ();

        DRMonsterCreater[] creaters = dtMonsterCreater.GetAllDataRows();

        foreach (DRMonsterCreater creater in creaters)
        {
            MonsterCreaterData monsterCreaterData = new MonsterCreaterData(EntityExtension.GenerateSerialId(), creater.Id);
            monsterCreaterData.Position = new Vector3(3, 0, 3);
            EntityExtension.ShowMonsterCreater(typeof(MonsterCreater), "MonsterCreaterGroup", monsterCreaterData);
        }
    }
예제 #4
0
    protected override void OnShow(object userData)
    {
        base.OnShow(userData);

        bulletData = userData as BulletData;
        if (bulletData == null)
        {
            Log.Error("Bullet data is invalid.");
            return;
        }

        leftEffectTimes           = 1;
        zeroSpeedAutoDestroyTimes = 0;

        CachedTransform.forward = bulletData.Forward;

        // 让子弹保持水平
        // CachedTransform.forward = new Vector3(
        //     CachedTransform.forward.x,
        //     1,
        //     CachedTransform.forward.z);

        if (bulletData.EffectId > 0)
        {
            BulletEffectData bulletEffectData = new BulletEffectData(EntityExtension.GenerateSerialId(), bulletData.EffectId, Id);
            EntityExtension.ShowBulletEffect(typeof(BulletEffect), "BulletEffectGroup", bulletEffectData);
        }
    }
예제 #5
0
    void OnTriggerEnter(Collider other)
    {
        Hero hero = other.gameObject.GetComponent <Hero> ();

        if (hero != null)
        {
            ParticleData data = new ParticleData(EntityExtension.GenerateSerialId(), magicWaterData.ParticleTypeID, this.Id);
            EntityExtension.ShowParticle(typeof(EParticle), "ParticleGroup", data);
        }
    }
예제 #6
0
    void OnTriggerStay(Collider other)
    {
        if (isMagicable == true)
        {
            isMagicable = false;

            Hero hero = other.gameObject.GetComponent <Hero> ();
            if (hero != null)
            {
                // 改变金币
                if (magicWaterData.AddGold != 0)
                {
                    int gold = PlayerData.Gold;
                    if (magicWaterData.AddGold < 0 && gold < Mathf.Abs(magicWaterData.AddGold))
                    {
                        return;
                    }

                    GameEntry.Setting.SetInt(Constant.Player.Gold, gold + magicWaterData.AddGold);
                    GameEntry.Event.Fire(this, ReferencePool.Acquire <RefreshGoldEventArgs> ());
                }

                // 改变血量
                if (magicWaterData.AddHPPercent != 0 &&
                    Mathf.Abs((int)(hero.HeroData.MaxHP * magicWaterData.AddHPPercent)) > Mathf.Abs(magicWaterData.AddHP))
                {
                    hero.OnDamage(-magicWaterData.AddHPPercent, true);
                }
                else if (magicWaterData.AddHP != 0)
                {
                    hero.OnDamage(-magicWaterData.AddHP, true);
                }

                // 改变攻击
                if (magicWaterData.AddAtk != 0)
                {
                    hero.PowerUpByAbsValue(0, 0, magicWaterData.AddAtk, 0);
                }

                // 生成克隆英雄
                if (magicWaterData.CreateCloneHeroTypeID != 0)
                {
                    MonsterData monsterData = new MonsterData(
                        EntityExtension.GenerateSerialId(), magicWaterData.CreateCloneHeroTypeID, CampType.CloneHero, 0);
                    monsterData.Position = new Vector3(transform.position.x, 0, transform.position.z);

                    // 避免克隆英雄太弱,根据玩家英雄实时最大血量调整克隆英雄属性
                    float powerPercent = hero.HeroData.MaxHP / monsterData.MaxHP / 100f + 1;
                    monsterData.AjustPower(powerPercent);

                    EntityExtension.ShowMonster(typeof(Monster), "MonsterGroup", monsterData);
                }
            }
        }
    }
    protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
    {
        base.OnUpdate(elapseSeconds, realElapseSeconds);

        timeCounter += elapseSeconds;
        pastTime    += elapseSeconds;

        if (pastTime < monsterCreaterData.StartTime)
        {
            return;
        }

        // 第一个创建的怪物跳过创建间隔
        if (createNum > 0 && timeCounter < monsterCreaterData.Interval)
        {
            return;
        }

        timeCounter = 0;

        // 创建怪物
        if (Utility.Random.GetRandom(100) < monsterCreaterData.Probability)
        {
            for (int i = 0; i < monsterCreaterData.PerNum; i++)
            {
                CampType camp = CampType.Enemy;

                MonsterData monsterData = new MonsterData(
                    EntityExtension.GenerateSerialId(), monsterCreaterData.MonsterTypeId, camp, monsterCreaterData.MonsterPrize);
                monsterData.Position = new Vector3(Utility.Random.GetRandom(5, 25), 0, Utility.Random.GetRandom(5, 25));

                // 调整怪物属性
                monsterData.AjustPower(monsterCreaterData.PowerPercent);
                monsterData.ChangeName(monsterCreaterData.Name);
                EntityExtension.ShowMonster(typeof(Monster), "MonsterGroup", monsterData);

                createNum++;
            }

            // 达到最大创建数量,销毁生成器
            if (createNum >= monsterCreaterData.MaxNum)
            {
                GameEntry.Entity.HideEntity(this.Id);
            }
        }
    }
예제 #8
0
    /// <summary>
    /// 执行攻击
    /// </summary>
    /// <param name="aimEntityID"></param>
    /// <param name="ownerAtk"></param>
    private void DoAttack(int ownerAtk)
    {
        CachedTransform.forward = parentTransform.forward;

        BulletData bulletData = new BulletData(
            EntityExtension.GenerateSerialId(),
            weaponData.BulletId,
            CachedTransform.forward,
            weaponData.OwnerCamp,
            weaponData.Attack + ownerAtk,
            weaponData.BulletSpeed
            );

        bulletData.Position = CachedTransform.position;

        EntityExtension.ShowBullet(typeof(Bullet), "BulletGroup", bulletData);

        //GameEntry.Sound.PlaySound(weaponData.BulletSoundId);
    }
예제 #9
0
    /// <summary>
    /// 界面打开。
    /// </summary>
    /// <param name="userData">用户自定义数据。</param>
    protected override void OnOpen(object userData)
    {
        base.OnOpen(userData);

        GlobalGame.totalPrize = 0;
        GlobalGame.killCount  = 0;

        RefreshGold();
        RefreshKillCount();

        HeroData heroData = new HeroData(EntityExtension.GenerateSerialId(), PlayerData.CurrentFightHeroID, CampType.Player);

        RefreshHeroMsg(heroData);

        /* 订阅事件 */
        GameEntry.Event.Subscribe(DeadEventArgs.EventId, OnDeadEvent);
        GameEntry.Event.Subscribe(RefreshHeroPropsEventArgs.EventId, OnRefreshHeroProps);
        GameEntry.Event.Subscribe(RefreshGoldEventArgs.EventId, OnRefreshGoldProps);
    }
예제 #10
0
    protected override void OnShow(object userData)
    {
        base.OnShow(userData);

        fightEntityData = userData as FightEntityData;
        if (fightEntityData == null)
        {
            Log.Error("fightEntityData is invalid.");
            return;
        }

        // CachedTransform.localScale = Vector3.one;

        manualWeapons.Clear();
        autoWeapons.Clear();
        skillWeapons.Clear();

        /* 附加血量条 */
        PowerBarData hpBarData = new PowerBarData(EntityExtension.GenerateSerialId(), 1, this.Id, CampType.Player);

        EntityExtension.ShowPowerBar(typeof(PowerBar), "PowerBarGroup", hpBarData);
    }
예제 #11
0
    public HeroData(int entityId, int typeId, CampType camp) : base(entityId, typeId, camp)
    {
        IDataTable <DRHero> dtHero = GameEntry.DataTable.GetDataTable <DRHero> ();
        DRHero drHero = dtHero.GetDataRow(typeId);

        if (drHero == null)
        {
            return;
        }

        Name                  = drHero.Name;
        HP                    = drHero.HP;
        MaxMP                 = drHero.MP;
        MaxHP                 = HP;
        MP                    = 0;
        MoveSpeed             = drHero.MoveSpeed;
        RotateSpeed           = drHero.RotateSpeed;
        Atk                   = drHero.Atk;
        AtkAnimTime           = drHero.AtkAnimTime;
        AtkRange              = drHero.AtkRange;
        Def                   = drHero.Def;
        AtkSpeed              = drHero.AtkSpeed;
        HPAbsorbPercent       = drHero.HPAbsorbPercent;
        DefAbsorbPercent      = drHero.DefAbsorbPercent;
        AtkAbsorbPercent      = drHero.AtkAbsorbPercent;
        AtkSpeedAbsorbPercent = drHero.AtkSpeedAbsorbPercent;
        HPMinAbsorb           = drHero.HPMinAbsorb;
        DefMinAbsorb          = drHero.DefMinAbsorb;
        AtkMinAbsorb          = drHero.AtkMinAbsorb;
        AtkSpeedMinAbsorb     = drHero.AtkSpeedMinAbsorb;

        for (int i = 0; i < drHero.GetWeaponCount(); i++)
        {
            weaponDatas.Add(new WeaponData(EntityExtension.GenerateSerialId(), drHero.GetWeaponID(i), Id, Camp));
        }
    }
예제 #12
0
    /// <summary>
    /// 真正执行伤害/加血逻辑
    /// </summary>
    /// <param name="damageHP">伤害值,可以正负,如果小于1,则按百分比执行</param>
    /// <param name="effectFollowMaxHP">是否以最大生命值为准</param>
    public void OnDamage(float damageHP, bool effectFollowMaxHP = false)
    {
        int changeHP = 0;

        // 按百分比改变当前血量
        if ((damageHP > 0 && damageHP < 1) || (damageHP < 0 && damageHP > -1))
        {
            if (effectFollowMaxHP)
            {
                changeHP = (int)(fightEntityData.MaxHP * damageHP);
            }
            else
            {
                changeHP = (int)(fightEntityData.HP * damageHP);
            }
        }
        else
        {
            changeHP = (int)damageHP;
        }

        bool forceAdd = false;

        // 伤害
        if (changeHP > 0)
        {
            changeHP -= fightEntityData.Def;

            if (changeHP < 0)
            {
                changeHP = 1;
            }

            if (changeHP > 0)
            {
                fightEntityData.HP -= changeHP;

                OnHurt();
            }
        }
        // 加血
        else if (changeHP < 0)
        {
            forceAdd = true;

            if (fightEntityData.HP - changeHP > fightEntityData.MaxHP)
            {
                changeHP = fightEntityData.HP - fightEntityData.MaxHP;
            }

            fightEntityData.HP += -changeHP;

            OnCure();
        }

        FlowTextData flowTextData = new FlowTextData(EntityExtension.GenerateSerialId(), this.Id, -changeHP, forceAdd);

        flowTextData.Position = this.CachedTransform.position + new Vector3(0.4f, 1, 0);
        flowTextData.Rotation = Camera.main.transform.rotation;

        EntityExtension.ShowFlowText(
            typeof(FlowText),
            "FlowTextGroup", flowTextData
            );

        // 更新血量条
        RefreshHPBar();

        if (fightEntityData.HP <= 0)
        {
            OnDead();
        }
    }
예제 #13
0
    public MonsterData(int entityId, int typeId, CampType camp, int prize) : base(entityId, typeId, camp)
    {
        IDataTable <DRMonster> dtMonster = GameEntry.DataTable.GetDataTable <DRMonster> ();
        DRMonster drMonster = dtMonster.GetDataRow(typeId);

        if (drMonster == null)
        {
            return;
        }

        Name  = drMonster.Name;
        LV    = drMonster.LV;
        exp   = drMonster.exp;
        HP    = drMonster.HP;
        MP    = drMonster.MP;
        MaxHP = HP;
        MaxMP = MP;
        S     = drMonster.S;
        A     = drMonster.A;
        D     = drMonster.D;
        I     = drMonster.I;
        M     = drMonster.M;
        C     = drMonster.C;
        L     = drMonster.L;

        Atk                = drMonster.Atk;
        Def                = drMonster.Def;
        MagicAtk           = drMonster.MagicAtk;
        MagicDef           = drMonster.MagicDef;
        AtkSpeed           = drMonster.AtkSpeed;
        Crit               = drMonster.Crit;
        CritDamage         = drMonster.CritDamage;
        Hit                = drMonster.Hit;
        Agl                = drMonster.Agl;
        Counter            = drMonster.Counter;
        Double             = drMonster.Double;
        HPRecoverPerSecond = drMonster.HPRecoverPerSecond;
        MPRecoverPerSecond = drMonster.MPRecoverPerSecond;

        BloodLine  = drMonster.BloodLine;
        Profession = drMonster.Profession;
        MP_STYLE   = drMonster.MP_STYLE;


        for (int i = 0; i < drMonster.GetWeaponCount(); i++)
        {
            weaponDatas.Add(new WeaponData(EntityExtension.GenerateSerialId(), drMonster.GetWeaponID(i), Id, Camp));
        }
        for (int i = 0; i < drMonster.GetSkillCount(); i++)
        {
            skillDatas.Add(new SkillData(EntityExtension.GenerateSerialId(), drMonster.GetSkillID(i), Id, Camp));
        }
        for (int i = 0; i < drMonster.GetJobCount(); i++)
        {
            jobDatas.Add(new JobData(EntityExtension.GenerateSerialId(), drMonster.GetJobID(i), Id, Camp));
        }
        for (int i = 0; i < drMonster.GetFeatureCount(); i++)
        {
            featureDatas.Add(new FeatureData(EntityExtension.GenerateSerialId(), drMonster.GetFeatureID(i), Id, Camp));
        }
        this.Prize = prize;

        for (int i = 0; i < drMonster.GetWeaponCount(); i++)
        {
            weaponDatas.Add(new WeaponData(EntityExtension.GenerateSerialId(), drMonster.GetWeaponID(i), Id, Camp));
        }
    }