コード例 #1
0
        /// <summary>
        /// 添加单位
        /// </summary>
        /// <param name="unit"></param>
        public void PlaceUnit(CombatUnit unit, int pos)
        {
            unit.Military = this;
            unit.BattleID = pos;
            unit.Position = pos.Int2Pos();

            _units.Add(unit);
            _aliveUnits.Add(unit);
            _unitsPos.Add(unit.Position, unit);
        }
コード例 #2
0
        public IEnumerable <CombatUnit> FindBy(CombatUnit self)
        {
            //return FindBy(self, Vector2.Zero);
            var military = _getMilitary(self);

            return(_range
                   .Select(loc => military.GetAliveUnitByPos(self.Position + loc * self.Military.Forward))
                   .Where(u => u != null)
                   .Take(_count));
        }
コード例 #3
0
        public CombatUnit CreateUnit(int unitID)
        {
            XElement xml;

            if (!Resources.Instance.UnitType.TryGetValue(unitID, out xml))
            {
                xml = new XElement("Unit",
                                   new XElement("ID", 0),
                                   new XElement("Type", "Action.War.CombatCampUnit"),
                                   new XElement("StrikeRange", ""),
                                   new XElement("Health", 1000),
                                   new XElement("SkillID", 0),
                                   new XElement("Charge", 0),
                                   new XElement("NormalAttack", 0),
                                   new XElement("NormalDefence", 0),
                                   new XElement("TacticAttack", 0),
                                   new XElement("TacticDefence", 0),
                                   new XElement("StrategyAttack", 0),
                                   new XElement("StrategyDefence", 0),
                                   new XElement("DodgeChance", 0),
                                   new XElement("BlockChance", 0),
                                   new XElement("CriticalChance", 0)
                                   );
            }
            var        t    = Type.GetType((string)xml.Element("Type"));
            CombatUnit unit = Activator.CreateInstance(t) as CombatUnit;

            unit.UnitTypeID  = unitID;
            unit.StrikeRange = RangeProvider.Generate((string)xml.Element("StrikeRange"));

            unit.Health    = (int)xml.Element("Health");
            unit.HealthMax = (int)xml.Element("Health");
            unit.SkillID   = (int)xml.Element("SkillID");
            unit.Charge    = (int)xml.Element("Charge");

            unit.NormalAttack    = (int)xml.Element("NormalAttack");
            unit.NormalDefence   = (int)xml.Element("NormalDefence");
            unit.TacticAttack    = (int)xml.Element("TacticAttack");
            unit.TacticDefence   = (int)xml.Element("TacticDefence");
            unit.StrategyAttack  = (int)xml.Element("StrategyAttack");
            unit.StrategyDefence = (int)xml.Element("StrategyDefence");

            unit.DodgeChance    = (float)xml.Element("DodgeChance");
            unit.BlockChance    = (float)xml.Element("BlockChance");
            unit.CriticalChance = (float)xml.Element("CriticalChance");

            //unit.CombatPower = unit.NormalAttack + unit.TacticAttack + unit.StrategyAttack;
            unit.CombatPower = Math.Max(unit.NormalAttack, Math.Max(unit.TacticAttack, unit.StrategyAttack));

            return(unit);
        }
コード例 #4
0
        protected override IEnumerable <BattleEffect> Attacking(CombatUnit target, AttackType attackType, BattleEffectType effectType)
        {
            if (effectType != BattleEffectType.Dodge && attackType == AttackType.Normal)
            {
                Charge += CHARGE_PLUS;
                yield return(new BattleEffect {
                    UnitSID = this.BattleID, PlusMP = CHARGE_PLUS
                });
            }

            foreach (var e in base.Attacking(target, attackType, effectType))
            {
                yield return(e);
            }
        }
コード例 #5
0
        /// <summary>
        /// 移动
        /// </summary>
        /// <param name="unit"></param>
        /// <returns></returns>
        public BattleAction Move(CombatUnit unit)
        {
            var pos = unit.Position + Vector2.UnitX * unit.Military.Forward;

            if (GetAliveUnitByPos(pos) != null)
            {
                return(null);
            }

            _unitsPos.Remove(unit.Position);
            unit.Position = pos;
            _unitsPos.Add(unit.Position, unit);

            var ba = new BattleAction();

            ba.UnitSID = unit.BattleID;
            ba.Type    = BattleActionType.Move;   // 移动
            ba.Param   = unit.Position.Pos2Int(); // 位置
            return(ba);
        }
コード例 #6
0
        /// <summary>
        /// 攻击计算
        /// </summary>
        /// <param name="target">攻击目标</param>
        /// <param name="attackType">攻击类型(普通、战法、策略)</param>
        /// <param name="effectType">攻击效果(闪避、格挡、重击)</param>
        /// <param name="damageRatio">伤害系数</param>
        /// <returns></returns>
        public IEnumerable <BattleEffect> DoAttack(CombatUnit target, AttackType attackType, BattleEffectType effectType, float damageRatio)
        {
            var ratio = (int)effectType;

            var damage = this._attack[attackType] - target._defence[attackType] + this.Level * 50;

            if (damage < 1)
            {
                damage = 1;
            }
            damage = (int)(damage * ratio * 0.5 * damageRatio);

            target.Health -= damage;

            var effect = new BattleEffect {
                UnitSID = target.BattleID, PlusHP = -damage, Type = effectType
            };

            return(Enumerable.Repeat(effect, 1)
                   .Concat(target.UnderAttack(effect)));
        }
コード例 #7
0
        public IEnumerable <CombatUnit> FindBy(CombatUnit self, Vector2 direction)
        {
            var military = _getMilitary(self);

            //var unitization = Vector2.Normalize(direction);
            //var invert = Vector2.Zero - unitization;
            //var matrix = new Matrix(unitization.X, unitization.Y, 0, 0, invert.Y, invert.X, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

            var angle  = (float)Math.Atan2(direction.Y, direction.X);
            var matrix = Matrix.CreateRotationZ(angle);

            return(_range
                   .Select(loc =>
            {
                var rotate = Vector2.Transform(loc, matrix);
                var pos = self.Position + direction + rotate;
                return military.GetAliveUnitByPos(new Vector2((float)Math.Round(pos.X), (float)Math.Round(pos.Y)));
            })
                   .Where(u => u != null)
                   .Take(_count));
        }
コード例 #8
0
 protected virtual IEnumerable <BattleEffect> Attacking(CombatUnit target, AttackType attackType, BattleEffectType effectType)
 {
     return(Enumerable.Empty <BattleEffect>());
 }
コード例 #9
0
 /// <summary>
 /// 死亡
 /// </summary>
 /// <param name="unit"></param>
 public void Die(CombatUnit unit)
 {
     _aliveUnits.Remove(unit);
     _unitsPos.Remove(unit.Position);
 }