Zone12201.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CommonAI.Zone;
  6. using CommonAI.Zone.ZoneEditor;
  7. using XmdsCommonServer.Plugin.Scene;
  8. using CommonAI.Data;
  9. using CommonAI.Zone.Instance;
  10. namespace XmdsCommonZone.Zones
  11. {
  12. /** 场景控制类 */
  13. [XmdsExtensionZone(12201)]
  14. public class Zone12201 : XmdsServerScene
  15. {
  16. private static readonly int S_MONSTER_ID = 1220101; //挂机怪id
  17. private static readonly int S_FOLLOWER_ID = 320009; //鲜花id
  18. // 总量信息
  19. private int mMonsterMax = 0;
  20. private int mFollowerMax = 0;
  21. private int mTotalCount = 0;
  22. //当前信息
  23. private int mCurMonsters = 0;
  24. private int mCurFollowers = 0;
  25. public Zone12201(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData gsData, string bindGameSrvId)
  26. : base(templates, listener, data, gsData, bindGameSrvId)
  27. {
  28. }
  29. protected override void baseInit(CommonAI.Zone.ZoneEditor.SceneData data, GSCreateAreaData gsData)
  30. {
  31. if(gsData == null)
  32. {
  33. Log.Error("Zone12201场景游戏服数据为空!");
  34. return;
  35. }
  36. this.mTotalCount = gsData.value1;
  37. this.mFollowerMax = gsData.value2;
  38. this.mMonsterMax = Math.Max(0, gsData.value1 - gsData.value2);
  39. OnTryAddUnit += OnTryAddUnitHandler;
  40. OnTryAddItem += OnTryAddItemHandler;
  41. OnUnitRemoved += OnUnitRemovedHandler;
  42. OnItemRemoved += OnItemRemoveHandler;
  43. }
  44. private bool OnTryAddUnitHandler(UnitInfo info)
  45. {
  46. // 锁定上限小怪id写死。
  47. if(info.UType != UnitInfo.UnitType.TYPE_MONSTER || info.ID != S_MONSTER_ID)
  48. {
  49. return true;
  50. }
  51. if(this.mCurMonsters >= this.mMonsterMax)
  52. {
  53. return false;
  54. }
  55. this.mCurMonsters++;
  56. //System.Console.WriteLine("怪物:" + this.mCurMonsters + " / " + this.mMonsterMax);
  57. return true;
  58. }
  59. private bool OnTryAddItemHandler(ItemTemplate info)
  60. {
  61. //挂机地图鲜花,写死
  62. if(info.ID != S_FOLLOWER_ID)
  63. {
  64. return true;
  65. }
  66. if(this.mCurFollowers >= this.mFollowerMax)
  67. {
  68. return false;
  69. }
  70. this.mCurFollowers++;
  71. //System.Console.WriteLine("鲜花数量:" + this.mCurFollowers + " / " + this.mFollowerMax);
  72. return true;
  73. }
  74. public void OnUnitRemovedHandler(InstanceZone zone, InstanceUnit obj)
  75. {
  76. if (obj.IsMonster && obj.Info.ID == S_MONSTER_ID)
  77. {
  78. this.mCurMonsters--;
  79. //System.Console.WriteLine("--怪物:" + this.mCurMonsters + " / " + this.mMonsterMax);
  80. if (this.mCurMonsters < 0)
  81. {
  82. Log.Error("OnUnitRemovedHandler monster num is error: " + this.mCurMonsters + ", " + this.mMonsterMax
  83. + ", " + this.mFollowerMax + ", " + this.mTotalCount);
  84. this.mCurMonsters = 0;
  85. }
  86. }
  87. }
  88. public void OnItemRemoveHandler(InstanceZone zone, InstanceItem obj)
  89. {
  90. if (obj.Info.ID != S_FOLLOWER_ID)
  91. {
  92. return ;
  93. }
  94. this.mCurFollowers--;
  95. //System.Console.WriteLine("--鲜花数量:" + this.mCurFollowers + " / " + this.mFollowerMax);
  96. if (this.mCurFollowers < 0)
  97. {
  98. Log.Error("OnItemRemoveHandler item num is error: " + this.mCurFollowers + ", " + this.mMonsterMax +
  99. ", " + this.mFollowerMax + ", " + this.mTotalCount);
  100. this.mCurFollowers = 0;
  101. }
  102. }
  103. /**游戏服场景标识通知*/
  104. public override void GSZoneFlagNotifyMsg(int value1)
  105. {
  106. this.mFollowerMax = Math.Max(this.mFollowerMax, value1);
  107. this.mMonsterMax = Math.Max(0, this.mTotalCount - this.mFollowerMax);
  108. //System.Console.WriteLine("--------notify:" + this.mFollowerMax + " -------- " + this.mMonsterMax);
  109. }
  110. }
  111. }