123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- using CommonAI.Data;
- using CommonAI.Zone;
- using CommonLang;
- using CommonLang.Geometry;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XmdsCommonServer.Plugin;
- using XmdsCommonServer.Plugin.Units;
- using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
- using XmdsCommonServer.XLS.Data;
- using static XmdsCommonServer.XLS.Data.XmdsSkillData;
- namespace XmdsCommonSkill.Plugin.Skills
- {
- /**
- * 召唤类boss机制:按照数量,时间,半径召唤小怪
- */
- public class XmdsSummonBase
- {
- protected XmdsSkillValue mSummonNums; // 单次数量,最大数量
- protected XmdsSkillValue mSummonLiftTime; // 召唤物ID, 生命时间
- protected int mSummonRange_Min; // 召唤半径
- protected int mSummonRange_Chg; // 召唤半径
- protected SummonType mSummonType = SummonType.guard;
- /// <summary>
- /// 召唤单位
- /// </summary>
- public void SummonUnit(XmdsVirtual master)
- {
- XmdsVirtual_Monster masterMonster = master as XmdsVirtual_Monster;
- //剩余可召唤数量
- int leftSummonCount = mSummonNums.GetValue(1, 2) - masterMonster.GetSummonUnitListCount();
- leftSummonCount = Math.Min(leftSummonCount, mSummonNums.GetValue(1, 1));
- if (leftSummonCount <= 0) { return; }
- UnitInfo info = XmdsBattleSkill.GetUnitInfo(mSummonLiftTime.GetValue(1, 1));
- for (int i = 0; i < leftSummonCount; i++)
- {
- this.ProcessSummonUnit(master, info, mSummonLiftTime.GetValue(1, 2));
- }
- }
- protected bool ProcessSummonUnit(XmdsVirtual master, UnitInfo info, int liftTime)
- {
- AddUnitEvent aue = null;
- //控制生命周期.
- info.LifeTimeMS = liftTime;
- Vector2 randomPos = this.RandomSummonPos(master);
-
- var unit = master.mUnit.Parent.AddUnit(
- info, "", master.mUnit.Force, master.GetUnitLv(), randomPos.X, randomPos.Y,
- master.mUnit.Direction, out aue, master.mUnit);
- //var monsterUnit = unit as XmdsInstanceMonster;
- //if (monsterUnit == null)
- //{
- // //log.Warn("添加召唤物失败:" + info.ID + ", " + this.SkillID);
- // return false;
- //}
- //if(this.mSummonType == SummonType.guard)
- //{
- // monsterUnit.guard();
- //}
- //else if(this.mSummonType == SummonType.guardMaster)
- //{
- // monsterUnit.guardUnit(master.mUnit);
- //}
- //else if (this.mSummonType == SummonType.attack)
- //{
- // //unit.followAndAttack(master.mUnit);
- //}
-
- XmdsVirtual_Monster materMonster = master as XmdsVirtual_Monster;
- materMonster.AddSummonUnitList(unit.Virtual as XmdsVirtual);
- return true;
- }
- // 默认直接按照半径来随机
- //protected Vector2 RandomSummonPos(XmdsVirtual master)
- //{
- // Vector2 randomPos = new Vector2();
- // int addX = master.mUnit.RandomN.Next() % 2 == 0 ? 1 : -1;
- // int addY = master.mUnit.RandomN.Next() % 2 == 0 ? 1 : -1;
- // float chgX = mSummonRange.GetValue(1) + (float)(master.mUnit.RandomN.NextDouble() * mSummonRange.GetValue(2));
- // float chgY = mSummonRange.GetValue(1) + (float)(master.mUnit.RandomN.NextDouble() * mSummonRange.GetValue(2));
- // randomPos.X = master.mUnit.X + chgX * addX;
- // randomPos.Y = master.mUnit.Y + chgY * addX;
- // return randomPos;
- //}
- //protected Vector2 RandomSummonPos(XmdsVirtual master)
- //{
- // Vector2 randomPos = new Vector2();
- // var pos = master.mUnit.Parent.PathFinder.FindNearRandomMoveableNode(
- // master.mUnit.RandomN, master.mUnit.X, master.mUnit.Y, mSummonRange_Min, true);
- // if (mSummonRange_Chg > 0)
- // {
- // randomPos.X = pos.PosX + (pos.PosX > master.mUnit.X ? 1 : -1) * mSummonRange_Chg;
- // randomPos.Y = pos.PosY + (pos.PosY > master.mUnit.Y ? 1 : -1) * mSummonRange_Chg;
- // }
- // System.Console.WriteLine("RandomSummonPos: " + randomPos.X + ", " + randomPos.Y);
- // return randomPos;
- //}
- protected Vector2 RandomSummonPos(XmdsVirtual master)
- {
- Vector2 randomPos = new Vector2();
- var pos = master.mUnit.Parent.PathFinder.FindNearRandomMoveableNode(
- master.mUnit.RandomN, master.mUnit.X, master.mUnit.Y, mSummonRange_Min, mSummonRange_Min + mSummonRange_Chg, true);
- randomPos.X = pos.PosX;
- randomPos.Y = pos.PosY;
- //System.Console.WriteLine("RandomSummonPos: " + randomPos.X + ", " + randomPos.Y);
- return randomPos;
- }
- public int GetSummonID()
- {
- return this.mSummonLiftTime.GetValue(1, 1);
- }
- public void InitConfig(SummonType summonType, XmdsSkillValue value1, XmdsSkillValue value2, XmdsSkillValue value3)
- {
- this.mSummonType = summonType;
- this.mSummonNums = value1;
- this.mSummonLiftTime = value2;
- this.mSummonRange_Min = value3.GetValue(1, 1);
- this.mSummonRange_Chg = Math.Max(0, value3.GetValue(1, 2) - mSummonRange_Min);
- }
- }
- }
|