public void FindAvaliableEnemyUnitTypes(Weapon ExecuteUnitWeapon, List <UnitTypeInfo> ParaUnitTypeInfoList)
    {
        for (int i = 0; i < UnitTypeNum; i++)
        {
            List <Unit> AttackableUnits = new List <Unit>();

            // 遍历该类型单位的每个单位并检查是否为当前攻击武器的合法攻击目标
            for (int j = 0; j < UnitsOfUnitName[UnitNameOfIndex[i]].Count; j++)
            {
                if (ExecuteUnitWeapon.ValidTargetUnit(UnitsOfUnitName[UnitNameOfIndex[i]][j]) == true && UnitsOfUnitName[UnitNameOfIndex[i]][j].GetAliveState() == true)
                {
                    AttackableUnits.Add(UnitsOfUnitName[UnitNameOfIndex[i]][j]);
                }
            }

            // 如果该类型单位中至少有一个合法的攻击单位则将该单位生成为一个单位类型信息的实例
            if (AttackableUnits.Count > 0)
            {
                UnitTypeInfo NewUnitTypeInfo = new UnitTypeInfo();

                NewUnitTypeInfo.SetParameter("UnitID", UnitNameOfIndex[i]);

                NewUnitTypeInfo.InitializeByUnitList(AttackableUnits);

                if (ParaUnitTypeInfoList == null)
                {
                    Debug.Log("ParaUnitTypeInfoList");
                }
                ParaUnitTypeInfoList.Add(NewUnitTypeInfo);
            }
        }
    }
Beispiel #2
0
        public Form1()
        {
            InitializeComponent();
            UnitTypeInfo  info = new UnitTypeInfo();
            XmlSerializer ser  = new XmlSerializer(typeof(UnitTypeInfo));

            ser.Serialize(File.OpenWrite(@"ui.xml"), info);
        }
    public override void ExcuteBattleOperation(Unit ExecuteUnit, BattleInfoSet ParaBattleInfoSet, BattleSequence ParaBattleSequence)
    {
        // 先锁定若干攻击单位
        for (int i = 0; i < TargetNum; i++)
        {
            // 将武器使用单位传入根据单位所有者来寻找敌对单位
            // 将武器本身引用传入是要根据武器的目标筛选标旗来选择合适的攻击单位类型
            if (ParaBattleInfoSet == null)
            {
                Debug.Log("ParaBattleInfoSet");
            }
            if (ExecuteUnit == null)
            {
                Debug.Log("ExecuteUnit");
            }


            List <UnitTypeInfo> EnemyUnitTypeList = ParaBattleInfoSet.FindAvaliableEnemyUnitTypes(ExecuteUnit, this);

            if (EnemyUnitTypeList == null)
            {
                Debug.Log("EnemyUnitTypeList");
            }

            if (EnemyUnitTypeList.Count > 0)
            {
                // 使用武器的单位类型选择器先选择一个单位类型
                UnitTypeInfo TargetUnitType = WeaponTargetUnitTypeSelector.ExecuteSingleSelection(EnemyUnitTypeList);

                // 再使用武器的单位选择器选择一个攻击目标单位
                Unit TargetUnit = WeaponTargetUnitSelector.ExecuteSingleSelection(TargetUnitType.GetContainUnit());

                // 再对攻击单位执行若干次武器开火效果
                for (int j = 0; j < MultipleAttacks; j++)
                {
                    Debug.Log(ExecuteUnit.GetUnitOwner() + " attack " + TargetUnit.GetUnitOwner());
                    WeaponEffect.ExcuteEffect(ExecuteUnit, TargetUnit, ParaBattleInfoSet, ParaBattleSequence);
                }
            }
            else
            {
                //此时没有敌方单位可以被攻击了
            }
        }

        // 可以再添加先进行多重攻击再进行多目标锁定的攻击模式
    }
Beispiel #4
0
        public FatherUnit(UnitTypeInfo info, string type, Vector2 pos)
            : base(UnitConverter.CreatePolygon(info.Polygon, pos))
        {
            this.Position = polygon.Center;
            this.Inertia  = info.Inertia;
            fullHp        = info.Health;
            Health        = info.Health;
            Defense       = new Damage(info.Defense);

            if ((info.Attacks.Length > 0) && !info.Attacks[0].Null)
            {
                mele = new ArealAttack(info.Attacks[0], this);
            }
            if (info.SpawnAttacks.Length != 0)
            {
                spAtk = new SpawnAttack(info.SpawnAttacks[0], this);
            }

            this.Type       = type;
            this.workPerSec = info.WorkPower;
            this.workPd     = info.WorkPeriod;

            this.MaxSpeed       = info.Speed;
            this.AI             = UnitConverter.CreateAI(info.AIType, this, MaxSpeed);
            this.CollisionClass = UnitConverter.CreateCollisionType(info.CollisionType);

            IdleAnimation   = UnitConverter.CreateAnimation(polygon, info.IdleAnimation);
            MoveAnimation   = UnitConverter.CreateAnimation(polygon, info.MoveAnimation);
            WorkAnimation   = UnitConverter.CreateAnimation(polygon, info.WorkAnimation);
            MeleeAnimation  = UnitConverter.CreateAnimation(polygon, info.MeleeAnimation);
            RangedAnimation = UnitConverter.CreateAnimation(polygon, info.RangedAnimation);

            SetBaseAnimation(IdleAnimation);

            this.SightRange = info.SightRange;

            unitMenu            = new ActorMenu(this);
            unitMenu.DisplayBar = true;

            IsRotatable = info.Rotatable;

            DrawDepth = Omron.Framework.DrawPriority.UnitDepth;
        }
Beispiel #5
0
        private void labelDragDrop_DragDrop(object sender, DragEventArgs e)
        {
            string[]       fileNames = (string[])e.Data.GetData(DataFormats.FileDrop);
            AttackTypeInfo inf       = new AttackTypeInfo();

            Serializer.Deserialize(File.ReadAllText(fileNames[0]), ref inf);
            XmlSerializer ser  = new XmlSerializer(typeof(UnitTypeInfo));
            UnitTypeInfo  info = null;

            try
            {
                info = (UnitTypeInfo)ser.Deserialize(File.OpenRead(fileNames[0]));
            }
            catch
            {
                MessageBox.Show("This ain't a valid unit");
                return;
            }
            textBoxUName.Text = Path.GetFileNameWithoutExtension(fileNames[0]);
            textBoxUType.Text = info.Type;
        }
Beispiel #6
0
        /*static Type[] okTypes = new Type[3] { typeof(int), typeof(string), typeof(float) };
         *
         * public static string GetValue(string xml, string key)
         * {
         *  string idStr = "<" + key + ">";
         *  int stInd = xml.IndexOf(idStr) + idStr.Length;
         *  int len = xml.IndexOf('<', stInd) - stInd;
         *  return xml.Substring(stInd, len);
         * }
         *
         * public static UnitTypeInfo Desserialize(string xml)
         * {
         *  UnitTypeInfo info = new UnitTypeInfo();
         *  FieldInfo[] props = info.GetType().GetFields();
         *  for (int i = 0; i < props.Length; i++)
         *  {
         *      if (okTypes.Contains(props[i].FieldType))
         *      {
         *          props[i].SetValue(info, ConvertTo(GetValue(xml, props[i].Name), props[i].FieldType));
         *      }
         *  }
         *  return info;
         * }*/

        public static string Serialize(UnitTypeInfo info)
        {
            return(null);
        }
Beispiel #7
0
 {//basic infantry unit. ********ranged atack then Melee attack
     public Infantry(UnitTypeInfo info, string type, Vector2 loc)
         : base(info, type, loc)
     {
     }