Ejemplo n.º 1
0
    public Tank CreateTank(TankSyncInfo syncInfo, int playerId = 0)
    {
        GamePlayerController player;

        GameManager.AllPlayers.TryGetValue(playerId, out player);

        GameObject obj  = GameObjectPool.instance.Instantiate(unitPrefab);
        TankNode   node = obj.GetComponent <TankNode>();
        Tank       unit = obj.GetComponent <Tank>();

        //TankController ctrl = obj.GetComponent<TankController>();

        ResourceManager.instance.LoadUnitModel(syncInfo.baseInfo.model);  // high time cost
        ResourceManager.instance.AssignModelToUnitNode(syncInfo.baseInfo.model, node);

        unit.m_id = syncInfo.id;
        node.m_id = syncInfo.id;
        AddUnit(unit);

        //unit.m_client = player;
        unit.m_model = syncInfo.baseInfo.model;
        if (localClient.isServer)
        {
            unit.AI = UnitAI.instance;
        }

        unit.Name      = syncInfo.baseInfo.name;
        unit.MaxHpBase = (float)syncInfo.baseInfo.maxHp;
        if (syncInfo.baseInfo.attackSkill.valid)
        {
            AttackAct atk = new AttackAct(syncInfo.baseInfo.attackSkill.name, (float)syncInfo.baseInfo.attackSkill.cd, new AttackValue(AttackValue.NameToType(syncInfo.baseInfo.attackSkill.type), (float)syncInfo.baseInfo.attackSkill.value), (float)syncInfo.baseInfo.attackSkill.vrange);
            atk.CastRange      = (float)syncInfo.baseInfo.attackSkill.range;
            atk.CastHorizontal = syncInfo.baseInfo.attackSkill.horizontal;
            foreach (var ani in syncInfo.baseInfo.attackSkill.animations)
            {
                atk.AddCastAnimation(ModelNode.NameToId(ani));
            }
            atk.ProjectileTemplate      = ResourceManager.instance.LoadProjectile(syncInfo.baseInfo.attackSkill.projectile);
            atk.ProjectileTemplate.fire = "Straight";
            unit.AddActiveSkill(atk);
        }

        node.position      = syncInfo.position;
        node.rotation      = syncInfo.rotation;
        unit.Hp            = syncInfo.hp;
        unit.force.Force   = syncInfo.force;
        unit.MoveSpeedBase = (float)syncInfo.baseInfo.move;
        unit.Revivable     = syncInfo.baseInfo.revivable;
        unit.Fixed         = syncInfo.baseInfo.isfixed;

        for (int i = 0; i < syncInfo.guns.Count; ++i)
        {
            unit.AddGun(i);
            unit.SetGunPosition(i, syncInfo.guns[i].position);
            unit.SetGunRotation(i, syncInfo.guns[i].rotation);
            //syncInfo.guns[i].rotateSpeed;
        }

        return(unit);
    }
Ejemplo n.º 2
0
    public SyncUnitInfo(Unit unit)
    {
        UnitNode node = unit.Node;

        baseInfo.model = unit.Model;
        baseInfo.name  = unit.Name;
        baseInfo.maxHp = unit.MaxHpBase;
        AttackAct attack = unit.AttackSkill as AttackAct;

        if (attack != null)
        {
            baseInfo.attackSkill            = new AttackInfo();
            baseInfo.attackSkill.cd         = attack.coolDownBase;
            baseInfo.attackSkill.type       = AttackValue.TypeToName(attack.AttackType);
            baseInfo.attackSkill.value      = attack.AttackValueBase;
            baseInfo.attackSkill.range      = attack.CastRange;
            baseInfo.attackSkill.horizontal = attack.CastHorizontal;
            List <int> castAnimations = attack.castAnimations;
            baseInfo.attackSkill.animations = new string[castAnimations.Count];
            for (int i = 0; i < castAnimations.Count; ++i)
            {
                baseInfo.attackSkill.animations[i] = ModelNode.IdToName(castAnimations[i]);
            }
            baseInfo.attackSkill.projectile = attack.ProjectileTemplate.Model;
        }

        position           = node.position;
        flippedX           = node.flippedX;
        hp                 = unit.Hp;
        force              = unit.force.Force;
        baseInfo.move      = unit.MoveSpeedBase;
        baseInfo.revivable = unit.Revivable;
        baseInfo.isfixed   = unit.Fixed;
    }
Ejemplo n.º 3
0
    public override Skill Clone()
    {
        AttackAct ret = new AttackAct(m_name, m_coolDown.x, m_attackValue, m_attackValueRandomRange.x);

        ret.CopyDataFrom(this);
        return(ret);
    }
Ejemplo n.º 4
0
    public override Skill Clone(string data)
    {
        AttackAct ret = new AttackAct(m_name, m_coolDown.x, m_attackValue, m_attackValueRandomRange.x);
        SkillData sd  = JsonUtility.FromJson <SkillData>(data);

        ret.CopyDataFrom(sd);
        return(ret);
    }
Ejemplo n.º 5
0
 public virtual void Act()
 {
     if (actTimer < actScheme.Count)
     {
         AttackAct a = actScheme[actTimer];
         if (a.Check(currFrame, this))
         {
             actTimer++;
         }
     }
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Server发起
    /// </summary>
    /// <param name="syncInfo"></param>
    /// <param name="playerId"></param>
    public Unit CreateUnit(SyncUnitInfo syncInfo, int playerId = 0)
    {
        localClient.ServerAddSyncAction(new SyncCreateUnit(syncInfo, playerId));

        GamePlayerController player;

        GameManager.AllPlayers.TryGetValue(playerId, out player);

        GameObject obj  = GameObjectPool.instance.Instantiate(unitPrefab);
        UnitNode   node = obj.GetComponent <UnitNode>();
        Unit       unit = obj.GetComponent <Unit>();

        ResourceManager.instance.LoadUnitModel(syncInfo.baseInfo.model);  // high time cost
        ResourceManager.instance.AssignModelToUnitNode(syncInfo.baseInfo.model, node);

        unit.m_id = syncInfo.id;
        node.m_id = syncInfo.id;
        AddUnit(unit);

        unit.m_model = syncInfo.baseInfo.model;
        if (isServer)
        {
            unit.AI = UnitAI.instance;
        }

        unit.Name = syncInfo.baseInfo.name;
        unit.InitHp(syncInfo.hp, (float)syncInfo.baseInfo.maxHp);
        if (syncInfo.baseInfo.attackSkill.valid)
        {
            AttackAct atk = new AttackAct(syncInfo.baseInfo.attackSkill.name, (float)syncInfo.baseInfo.attackSkill.cd, new AttackValue(AttackValue.NameToType(syncInfo.baseInfo.attackSkill.type), (float)syncInfo.baseInfo.attackSkill.value), (float)syncInfo.baseInfo.attackSkill.vrange);
            atk.CastRange      = (float)syncInfo.baseInfo.attackSkill.range;
            atk.CastHorizontal = syncInfo.baseInfo.attackSkill.horizontal;
            foreach (string ani in syncInfo.baseInfo.attackSkill.animations)
            {
                atk.AddCastAnimation(ModelNode.NameToId(ani));
            }
            atk.ProjectileTemplate = ResourceManager.instance.LoadProjectile(syncInfo.baseInfo.attackSkill.projectile);
            unit.AddActiveSkill(atk);
        }
        node.position = syncInfo.position;
        node.SetFlippedX(syncInfo.flippedX);
        unit.force.Force    = syncInfo.force;
        unit.MoveSpeedBase  = (float)syncInfo.baseInfo.move;
        unit.Revivable      = syncInfo.baseInfo.revivable;
        unit.Fixed          = syncInfo.baseInfo.isfixed;
        unit.level.MaxLevel = 100;
        unit.level.Level    = 10;

        if (player != null)
        {
            // 玩家单位
            Debug.LogFormat("CreateUnit, unitId({0}) <-> playerId({1}).", unit.Id, player.playerId);
            if (player == localClient)
            {
                Debug.LogFormat("That's Me, {0}.", unit.Name);
            }

            // TEST !!!!
            unit.InitHp(5000, 5000);
            unit.AttackSkill.coolDownBase       = 2.0f;
            unit.AttackSkill.coolDownSpeedCoeff = 2;
            unit.CriticalRateBase   = 0.2f;
            unit.CriticalDamageBase = 20.0f;

            SplashPas splash = new SplashPas("SplashAttack", 0.5f, new Coeff(0.75f, 0), 1f, new Coeff(0.25f, 0));
            unit.AddPassiveSkill(splash);

            if (player == localClient)
            {
                BattleWorldUI.Current.portraitGroup.AddPortrait(unit);
            }
        }

        node.SetFrame(ModelNode.kFrameDefault);
        CreateUnitHUD(unit);
        return(unit);
    }
Ejemplo n.º 7
0
 private void TryHandleAttackAction(GameAction action)
 {
     if (action.SubType != "ATTACK") return;
     var attackAct = new AttackAct();
     attackAct.Target = action.Target.Card;
     attackAct.Entity = action.Entity.Card;
     CurrentTurn.Acts.Add(attackAct);
 }