123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683 |
- using CommonAI.Zone.Instance;
- using CommonAI.Zone.ZoneEditor;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using XmdsCommon.Plugin;
- using CommonAI.Zone;
- using CommonAI.Zone.Attributes;
- using CommonAI.Zone.Helper;
- using XmdsCommonServer.Plugin.Units;
- using XmdsCommonServer.Plugin.Quest;
- using XmdsCommon.EditorData;
- using CommonLang;
- using CommonLang.Vector;
- using CommonAI.RTS.Manhattan;
- using XmdsCommon.Message;
- using CommonAI.Data;
- using CommonAI.ZoneServer.JSGModule;
- namespace XmdsCommonServer.Plugin.Scene
- {
-
-
-
- public class XmdsServerScene : EditorScene
- {
-
-
-
-
-
- public delegate void ObjectForEachAction<T>(T obj, ref bool cancel) where T : class;
- private HashMap<int, List<ZoneRegion>> mRebirthRegionMap = new HashMap<int, List<ZoneRegion>>();
- public XmdsServerScene(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData gsData, string bindGameSrvId, int spaceDiv = 11)
- : this(templates, listener, data, gsData, spaceDiv, DateTime.Now.Millisecond, bindGameSrvId)
- { }
- protected XmdsServerScene(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData gsData, int spaceDiv, int rarndomSeed, string bindGameSrvId)
- : base(templates, listener, data, gsData, spaceDiv, rarndomSeed)
- {
- this.OnQuestAccepted += XmdsServerScene_OnQuestAccepted;
- this.OnQuestDropped += XmdsServerScene_OnQuestDropped;
- this.OnQuestCommitted += XmdsServerScene_OnQuestCommitted;
- this.OnQuestStatusChanged += XmdsServerScene_OnQuestStatusChanged;
- this.OnPlayerReady += XmdsServerScene_OnPlayerReady;
-
- this.mKingID = XmdsDataMgr.GetInstance().GetMapKingID(this.GetSceneID());
- this.mBindGameSrvId = bindGameSrvId;
- }
- protected override void InitTerrain(SceneData data, int spaceDiv, out ZoneManhattanMap terrain_data, out AstarManhattan path_finder, out ManhattanMapAreaGenerator area_gen)
- {
-
-
- base.InitTerrain(data, spaceDiv, out terrain_data, out path_finder, out area_gen);
- }
-
-
-
-
-
-
- #region _任务相关_
- private void XmdsServerScene_OnPlayerReady(InstancePlayer player)
- {
- XmdsInstancePlayer p = player as XmdsInstancePlayer;
- var list = p.GetQuests();
- foreach (var q in list)
- {
- QuestScriptManager.CreateQuestScript(q.QuestID, p);
- }
- }
- private void XmdsServerScene_OnQuestStatusChanged(InstancePlayer player, string quest, string key, string value)
- {
- if (key == XmdsQuestData.Attribute_InitOK)
- {
- QuestScriptManager.CreateQuestScript(quest, player as XmdsInstancePlayer);
- }
- else
- {
- QuestScriptManager.QuestStatusChanged(quest, player as XmdsInstancePlayer, key, value);
- }
- }
- private void XmdsServerScene_OnQuestAccepted(InstancePlayer player, string quest)
- {
-
-
- }
- private void XmdsServerScene_OnQuestCommitted(InstancePlayer player, string quest)
- {
- QuestScriptManager.ClearQuestScript(quest, player as XmdsInstancePlayer);
- }
- private void XmdsServerScene_OnQuestDropped(InstancePlayer player, string quest)
- {
- QuestScriptManager.ClearQuestScript(quest, player as XmdsInstancePlayer);
- }
- #endregion
-
- #region _AOI_相关_
- public override bool IsTeammates(InstanceUnit src, InstanceUnit dst)
- {
- if (src != null && dst != null)
- {
- var s_v = src.Virtual as XmdsVirtual;
- var d_v = dst.Virtual as XmdsVirtual;
- return d_v.IsTeamMember(s_v.GetPlayerUUID());
- }
- return false;
- }
- public override bool IsVisibleAOI(InstanceZoneObject src, InstanceZoneObject dst)
- {
- if (src is XmdsInstancePlayer)
- {
- XmdsInstancePlayer player = src as XmdsInstancePlayer;
- if (!player.IsPlayerReady())
- {
- return false;
- }
- String bindPlayerId = dst.GetBindPlayerId();
- if(bindPlayerId != null && bindPlayerId != player.PlayerUUID)
- {
- return false;
- }
- }
-
- if (src.AoiStatus == dst.AoiStatus)
- {
- var dstUnit = dst as InstanceUnit;
- if (dstUnit == null)
- {
- return true;
- }
-
-
-
-
-
-
-
-
- if (dstUnit.IsVisible)
- {
- return true;
- }
- if (IsTeammates(src as InstanceUnit, dstUnit))
- {
- return (dstUnit.Virtual as XmdsVirtual).TeamMemberVisible;
- }
- return false;
- }
-
-
-
-
-
-
-
-
- return base.IsVisibleAOI(src, dst);
- }
- #endregion
- #region Attack.
- public override bool IsAttackable(InstanceUnit src, InstanceUnit target, SkillTemplate.CastTarget expectTarget, AttackReason reason, ITemplateData weapon)
- {
-
-
-
-
-
- var sp = (src.Virtual as XmdsVirtual);
- if (sp == null)
- {
- Log.Error("IsAttackable src or src.Virtual is null");
- return false;
- }
- var dp = (target.Virtual as XmdsVirtual);
- if (dp == null)
- {
- Log.Error("IsAttackable target or target.Virtual is null");
- return false;
- }
- #region 安全区域检测. 宠物不会是目标
- if (expectTarget == SkillTemplate.CastTarget.Enemy && target.IsPlayerUnit && src.IsPlayerUnit)
- {
- if (target.Virtual.IsInSafeArea() || src.Virtual.IsInSafeArea())
- {
- return false;
- }
- }
- #endregion
- #region 中立单位检测.
- if (target.Force == 0)
- {
- return false;
- }
- #endregion
- #region 无敌单位.
- if (target.IsInvincible && expectTarget == SkillTemplate.CastTarget.Enemy)
- {
- return false;
- }
-
- if (!String.IsNullOrEmpty(src.GetAttackPlayer()))
- {
- if(target.PlayerUUID == null || target.PlayerUUID != src.GetAttackPlayer())
- {
- return false;
- }
- }
-
- if (src != target && (!src.IsPlayerUnit || !JSGModule.IsExpectValidForPet(expectTarget)))
- {
-
- if (src.IsPet)
- {
-
- if (target.IsPet || (target.IsPlayer && src.Virtual.GetMasterID() != target.ID))
- {
- return false;
- }
- }
-
- else if (target.IsPet)
- {
-
-
- {
- return false;
- }
- }
- }
-
- if(!String.IsNullOrEmpty(target.GetAttackPlayer()) && src.PlayerUUID != target.GetAttackPlayer())
- {
- if (src.IsPet && src.Virtual.GetMasterUnit() != null)
- {
- if (src.Virtual.GetMasterUnit().PlayerUUID != target.GetAttackPlayer())
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- #endregion
- #region 隐形对攻击的影响.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #endregion
- #region 位面检测.
-
- if (reason != AttackReason.Attack && !IsVisibleAOI(src, target))
- {
-
- return false;
- }
- #endregion
- #region PK等级保护.
- if (((target.Virtual) as XmdsVirtual).IsAttackable(src.Virtual as XmdsVirtual) == false)
- {
- return false;
- }
- #endregion
- #region 技能目标单位类型状态检测.
-
- var unit_type = XmdsSkillProperties.TargetUnitType.ALL;
- if (weapon is SkillTemplate && reason == AttackReason.Attack)
- {
- unit_type = ((weapon as SkillTemplate).Properties as XmdsSkillProperties).NeedTargetType;
- }
- else if (weapon is SpellTemplate && reason == AttackReason.Attack)
- {
- unit_type = ((weapon as SpellTemplate).Properties as XmdsSpellProperties).NeedTargetType;
- }
- switch (unit_type)
- {
- case XmdsSkillProperties.TargetUnitType.Monster:
- if (!(dp is XmdsVirtual_Monster))
- {
- return false;
- }
- break;
- case XmdsSkillProperties.TargetUnitType.Player:
- if (!(dp is XmdsVirtual_Player))
- {
- return false;
- }
- break;
- case XmdsSkillProperties.TargetUnitType.ExcpetPlayer:
- if ((dp is XmdsVirtual_Player))
- {
- return false;
- }
- break;
- }
- bool onlyForDead = false;
-
- if (src.CurrentState != null)
- {
- InstanceUnit.State s = src.CurrentState;
- InstanceUnit.StateSkill ss = s as InstanceUnit.StateSkill;
- if (ss != null)
- {
- if ((ss.SkillData.Properties as XmdsSkillProperties).TargetType == XmdsSkillProperties.XmdsSkillTargetType.AllianceDead)
- {
-
- onlyForDead = true;
- }
- }
- }
- if (!target.IsActive)
- {
- if (onlyForDead)
- {
-
-
- return (target is XmdsInstancePlayer);
- }
- return false;
- }
- else
- {
-
- if (onlyForDead == false)
- {
- switch (expectTarget)
- {
- case SkillTemplate.CastTarget.Enemy:
-
- return !(src.Virtual as XmdsVirtual).IsAllies((target.Virtual as XmdsVirtual), expectTarget, reason);
- case SkillTemplate.CastTarget.PetForMaster:
-
-
-
-
-
- if(src is InstancePet)
- {
- InstancePet pet = src as InstancePet;
- if(pet != null && pet.Master == target)
- {
- return true;
- }
- }
- return false;
- case SkillTemplate.CastTarget.EveryOne:
- return JudgeEveryOneAttackable(src, target, expectTarget);
- case SkillTemplate.CastTarget.Alias:
- case SkillTemplate.CastTarget.AlliesExcludeSelf:
-
- if (!(src.Virtual as XmdsVirtual).IsAllies((target.Virtual as XmdsVirtual), expectTarget, reason))
- return false;
- if (src == target) { return false; }
- return (src.Virtual as XmdsVirtual).IsTeamMember(target);
- case SkillTemplate.CastTarget.AlliesIncludeSelf:
-
- if (!(src.Virtual as XmdsVirtual).IsAllies((target.Virtual as XmdsVirtual), expectTarget, reason))
- return false;
- return (src.Virtual as XmdsVirtual).IsTeamMember(target);
-
- case SkillTemplate.CastTarget.EveryOneExcludeSelf:
- return JudgeEveryOneAttackable(src, target, expectTarget);
- case SkillTemplate.CastTarget.Self:
- return src == target;
- case SkillTemplate.CastTarget.EnemyAndSelf:
- return src == target || !(src.Virtual as XmdsVirtual).IsAllies((target.Virtual as XmdsVirtual), expectTarget, reason);
- case SkillTemplate.CastTarget.NA:
- default:
- return false;
- }
- }
- return false;
- }
- #endregion
- }
-
- private bool JudgeEveryOneAttackable(InstanceUnit src, InstanceUnit target, SkillTemplate.CastTarget expectTarget)
- {
-
-
-
-
-
-
-
-
- if (SkillTemplate.CastTarget.EveryOneExcludeSelf == expectTarget && src == target)
- {
- return false;
- }
- switch (src.Virtual.GetCurPKMode())
- {
- case PKMode.Peace:
- if (src.Virtual.GetForceID() == target.Virtual.GetForceID())
- {
- return src.Virtual.IsAllies(target.Virtual, true, true);
- }
- return true;
- case PKMode.force:
- if (src.Virtual.GetForceID() == target.Virtual.GetForceID())
- {
- return false;
- }
- return !src.Virtual.IsAllies(target.Virtual, true, true);
- case PKMode.Guild:
- if (src.Virtual.IsGuildMember(target.Virtual.GetGuildID()))
- {
- return false;
- }
- return !src.Virtual.IsAllies(target.Virtual, true, true);
- case PKMode.Team:
- return !src.Virtual.IsAllies(target.Virtual, true, true);
- case PKMode.All:
- return !(src == target);
- case PKMode.Justice:
- if (target.Virtual.GetCurPKLevel() == PKLevel.White)
- {
- return false;
- }
- return !src.Virtual.IsAllies(target.Virtual, true, true); ;
- case PKMode.Server:
- if (src.Virtual.IsServerMember(target.Virtual.GetServerID()))
- {
- return false;
- }
- return !src.Virtual.IsAllies(target.Virtual, true, true); ;
- }
- return false;
- }
- #endregion
- #region Region相关.
- protected override void InitEditRegion(RegionData rdata)
- {
- base.InitEditRegion(rdata);
-
- ZoneRegion flag = getFlag(rdata.Name) as ZoneRegion;
- if (flag != null && rdata.Abilities != null)
- {
- List<ZoneRegion> temp = null;
- foreach (AbilityData td in rdata.Abilities)
- {
- if (td is XmdsRebirthAbility)
- {
- XmdsRebirthAbility zra = td as XmdsRebirthAbility;
- if (mRebirthRegionMap.TryGetValue(zra.START_Force, out temp))
- {
- temp.Add(flag);
- }
- else
- {
- temp = new List<ZoneRegion>();
- temp.Add(flag);
- mRebirthRegionMap.Add(zra.START_Force, temp);
- }
- }
- }
- }
- }
-
-
-
-
-
- public void ForEachRebirthRegion(int force, Action<ZoneRegion> action)
- {
- List<ZoneRegion> temp = null;
- if (mRebirthRegionMap.TryGetValue(force, out temp))
- {
- for (int i = temp.Count - 1; i >= 0; --i)
- {
- var rg = temp[i];
- action(rg);
- }
- }
- }
-
-
-
-
-
-
-
- public ZoneRegion GetNearestRebirthRegion(float x, float y, int regionForce)
- {
- using (var list = ListObjectPool<ZoneRegion>.AllocAutoRelease())
- {
- ZoneRegion ret = null;
- float min_value = float.MaxValue;
- float len;
- this.ForEachRebirthRegion(regionForce, (rg) =>
- {
- if (rg.Enable)
- {
- len = MathVector.getDistanceSquare(x, y, rg.X, rg.Y);
- if (len < min_value)
- {
- min_value = len;
- ret = rg;
- }
- }
- });
- return ret;
- }
- }
-
-
-
-
-
- public ZoneRegion GetRandomRebirthRegion(int regionForce)
- {
- using (var list = ListObjectPool<ZoneRegion>.AllocAutoRelease())
- {
- ZoneRegion ret = null;
- List<ZoneRegion> temp = null;
- mRebirthRegionMap.TryGetValue(regionForce, out temp);
-
- if(temp == null)
- {
- mRebirthRegionMap.TryGetValue(-1, out temp);
- }
- if (temp != null)
- {
- int num = RandomN.Next(0, temp.Count);
- if (num > temp.Count)
- {
- num = temp.Count - 1;
- }
- return temp[num];
- }
- return ret;
- }
- }
-
-
-
-
-
- public List<ZoneRegion> GetRebirthRegions(byte startForce)
- {
- List<ZoneRegion> ret = null;
- if (mRebirthRegionMap != null)
- {
- mRebirthRegionMap.TryGetValue(startForce, out ret);
- }
- return ret;
- }
- #endregion
- #region Events
- internal void callback_OnCombatStateChange(InstanceUnit unit, BattleStatus status)
- {
- if (mOnCombatStateChange != null)
- {
- mOnCombatStateChange.Invoke(unit, status);
- }
- }
- public delegate void CombatStateChangeHandler(InstanceUnit unit, BattleStatus status);
- [EventTriggerDescAttribute("单位战斗状态改变")]
- public event CombatStateChangeHandler OnCombatStateChange { add { mOnCombatStateChange += value; } remove { mOnCombatStateChange -= value; } }
- private CombatStateChangeHandler mOnCombatStateChange;
- protected override void ClearEvents()
- {
- mOnCombatStateChange = null;
- base.ClearEvents();
- }
- #endregion
- }
- }
|