Guest User

Untitled

a guest
Jan 6th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using DOL.GS;
  7. using DOL.Database;
  8. using DOL.GS.PacketHandler;
  9. namespace DOL.GS.Scripts
  10. {
  11. public class CloneInstance : Instance
  12. {
  13. public CloneInstance(ushort ID, GameTimer.TimeManager time, RegionData dat)
  14. : base(ID, time, dat)
  15. {
  16. }
  17.  
  18.  
  19. //Change instance level...
  20. //I've checked, this should be called correctly: player will be added/removed in time.
  21. public override void OnPlayerEnterInstance(GamePlayer player)
  22. {
  23. base.OnPlayerEnterInstance(player);
  24. UpdateInstanceLevel();
  25.  
  26.  
  27. // player.Out.SendMessage("This instance is currently level " + m_level + ".", eChatType.CT_Important, eChatLoc.CL_SystemWindow);
  28. }
  29.  
  30. public override void OnPlayerLeaveInstance(GamePlayer player)
  31. {
  32. base.OnPlayerLeaveInstance(player);
  33. UpdateInstanceLevel();
  34. }
  35.  
  36. public override void LoadFromDatabase(string instanceName)
  37. {
  38. base.LoadFromDatabase(instanceName);
  39. Assembly gasm = Assembly.GetAssembly(typeof(GameServer));
  40.  
  41.  
  42. IList<Mob> mobs = GameServer.Database.SelectObjects<Mob>("`Region` = '" + Skin.ToString() + "'");
  43. if (mobs.Count > 0)
  44. {
  45. foreach (Mob mob in mobs)
  46. {
  47. GameNPC myMob = null;
  48. string error = string.Empty;
  49.  
  50. if (mob.Guild.Length > 0 && mob.Realm >= 0 && mob.Realm <= (int)eRealm._Last)
  51. {
  52. Type type = ScriptMgr.FindNPCGuildScriptClass(mob.Guild, (eRealm)mob.Realm);
  53. if (type != null)
  54. {
  55. try
  56. {
  57. Type[] constructorParams;
  58. if (mob.NPCTemplateID != -1)
  59. {
  60. constructorParams = new Type[] { typeof(INpcTemplate) };
  61. ConstructorInfo handlerConstructor = typeof(GameNPC).GetConstructor(constructorParams);
  62. INpcTemplate template = NpcTemplateMgr.GetTemplate(mob.NPCTemplateID);
  63. myMob = (GameNPC)handlerConstructor.Invoke(new object[] { template });
  64. }
  65. else
  66. {
  67. myMob = (GameNPC)type.Assembly.CreateInstance(type.FullName);
  68. }
  69. }
  70. catch (Exception e)
  71. {
  72. }
  73. }
  74. }
  75.  
  76.  
  77. if (myMob == null)
  78. {
  79. string classtype = ServerProperties.Properties.GAMENPC_DEFAULT_CLASSTYPE;
  80.  
  81. if (mob.ClassType != null && mob.ClassType.Length > 0 && mob.ClassType != Mob.DEFAULT_NPC_CLASSTYPE)
  82. {
  83. classtype = mob.ClassType;
  84. }
  85.  
  86. try
  87. {
  88. myMob = (GameNPC)gasm.CreateInstance(classtype, false);
  89. }
  90. catch
  91. {
  92. error = classtype;
  93. }
  94.  
  95. if (myMob == null)
  96. {
  97. foreach (Assembly asm in ScriptMgr.Scripts)
  98. {
  99. try
  100. {
  101. myMob = (GameNPC)asm.CreateInstance(classtype, false);
  102. error = string.Empty;
  103. }
  104. catch
  105. {
  106. error = classtype;
  107. }
  108.  
  109. if (myMob != null)
  110. break;
  111. }
  112.  
  113. if (myMob == null)
  114. {
  115. myMob = new GameNPC();
  116. error = classtype;
  117. }
  118. }
  119. }
  120.  
  121. // if (!allErrors.Contains(error))
  122. //allErrors += " " + error + ",";
  123.  
  124. if (myMob != null)
  125. {
  126. try
  127. {
  128. myMob.LoadFromDatabase(mob);
  129. myMob.CurrentRegionID = this.ID;
  130. myMob.RespawnInterval = -1;
  131.  
  132. if (myMob is GameMerchant)
  133. {
  134. // myMerchantCount++;
  135. }
  136. else
  137. {
  138. // myMobCount++;
  139. }
  140. }
  141. catch (Exception e)
  142. {
  143. throw;
  144. }
  145.  
  146. myMob.AddToWorld();
  147.  
  148. if (myMob.Name.ToLower() == "spawn-in")
  149. {
  150. m_entranceLocation = new GameLocation(instanceName + "entranceRegion" + ID, ID, myMob.X, myMob.Y, myMob.Z, myMob.Heading);
  151. }
  152. }
  153. }
  154.  
  155. }
  156. else
  157. {
  158. }
  159. }
  160. //This void is outside of Instance,
  161. //because i want people to think carefully about how they change levels in their instance.
  162. public void UpdateInstanceLevel()
  163. {
  164. }
  165.  
  166. /// <summary>
  167. /// Expire the missions - the instance has exploded.
  168. /// </summary>
  169. public override void OnCollapse()
  170. {
  171. //We expire the mission as players can no longer reach or access the region once collapsed.
  172. base.OnCollapse();
  173. }
  174. }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment