IntelligentCreatureObject.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects
  6. {
  7. public class IntelligentCreatureObject : MonsterObject
  8. {
  9. public bool Summoned;
  10. public string CustomName { get { return CreatureInfo.CustomName; } set { CreatureInfo.CustomName = value; } }
  11. public UserIntelligentCreature CreatureInfo;
  12. public IntelligentCreatureType PetType = IntelligentCreatureType.None;
  13. public ItemGrade GradeFilter = ItemGrade.None;
  14. public IntelligentCreatureRules CreatureRules = new IntelligentCreatureRules();
  15. public IntelligentCreatureItemFilter ItemFilter { get { return CreatureInfo.Filter; } set { CreatureInfo.Filter = value; } }
  16. public IntelligentCreaturePickupMode CurrentPickupMode { get { return CreatureInfo.petMode; } set { CreatureInfo.petMode = value; } }
  17. public List<MapObject> TargetList = new List<MapObject>();
  18. public bool FillingTargetList = false;
  19. public bool DoTargetList = false;
  20. public bool TargetListTargetClean = false;
  21. public int Fullness { get { return CreatureInfo.Fullness; } set { CreatureInfo.Fullness = value; } }
  22. public long FullnessTicker = 0;
  23. public const long FullnessDelay = Settings.Second;
  24. public bool DoDelayedPickup = false;
  25. public long DelayedpickupTicker = 0;
  26. public const long DelayedpickupDelay = Settings.Second;//1 second
  27. public long CreatureTime;
  28. public long BlackstoneTime { get { return CreatureInfo.BlackstoneTime; } set { CreatureInfo.BlackstoneTime = value; } }
  29. public const long BlackstoneProduceTime = 10800;//3 hours in seconds
  30. public long PearlTicker = 0;
  31. public const long PearlProduceCount = 1000;//1000 items = 1 pearl
  32. public long AnimvariantTicker = 0;
  33. public const long AnimvariantDelay = 10 * Settings.Second;//10 seconds
  34. public long MaintainfoodTime { get { return CreatureInfo.MaintainFoodTime; } set { CreatureInfo.MaintainFoodTime = value; } }
  35. public long TimedSayTicker = 0;
  36. public const long TimedSayDelay = 20 * Settings.Second;
  37. private bool shortcheck = true;
  38. public override bool Blocking
  39. {
  40. get
  41. {
  42. return false;
  43. }
  44. }
  45. protected override bool CanMove
  46. {
  47. get
  48. {
  49. return Envir.Time > MoveTime && Envir.Time > ActionTime;
  50. }
  51. }
  52. public override string Name
  53. {
  54. get { return Master == null ? CustomName : (Dead ? CustomName : GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.CustomNameMastersPet), CustomName, Master.Name)); }
  55. set { throw new NotSupportedException(); }
  56. }
  57. protected override bool CanAttack
  58. {
  59. get
  60. {
  61. return !Dead && Envir.Time > AttackTime && Envir.Time > ActionTime;
  62. }
  63. }
  64. public override ObjectType Race
  65. {
  66. get { return ObjectType.Creature; }
  67. }
  68. public override bool IgnoresNoPetRestriction => true;
  69. public IntelligentCreatureObject(MonsterInfo info) : base(info)
  70. {
  71. ActionTime = Envir.Time + 1000;
  72. PetType = (IntelligentCreatureType)info.Effect;
  73. }
  74. public override void SetOperateTime()
  75. {
  76. base.SetOperateTime();
  77. var time = OperateTime;
  78. if (CreatureTime < time && CreatureTime > Envir.Time)
  79. time = RoamTime;
  80. if (OperateTime <= Envir.Time || time < OperateTime)
  81. OperateTime = time;
  82. }
  83. public override void Process()
  84. {
  85. RefreshNameColour();
  86. if (Target != null && (Target.CurrentMap != CurrentMap || !Functions.InRange(CurrentLocation, Target.CurrentLocation, Globals.DataRange)))
  87. Target = null;
  88. if (Dead && Envir.Time >= DeadTime)
  89. {
  90. CurrentMap.RemoveObject(this);
  91. if (Master != null)
  92. {
  93. Master.Pets.Remove(this);
  94. Master = null;
  95. }
  96. Despawn();
  97. return;
  98. }
  99. if (Envir.Time > CreatureTime)
  100. {
  101. CreatureTime = Envir.Time + Settings.Second;
  102. ProcessBlackStoneProduction();
  103. ProcessMaintainFoodBuff();
  104. }
  105. if (Fullness == 0)//unable to operate with food level 0
  106. {
  107. CreatureTimedSay(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.IAmStarving));
  108. return;
  109. }
  110. DecreaseFullness(1);//Decrease Feeding
  111. if (DoDelayedPickup && Target != null && DoTargetList)//delayed pickup
  112. {
  113. if (Envir.Time > DelayedpickupTicker)
  114. {
  115. PickupAllItems(Target.CurrentLocation);
  116. Target = null;
  117. DoDelayedPickup = false;
  118. if (TargetList.Count > 0)
  119. {
  120. TargetList.RemoveAt(0);
  121. }
  122. if (TargetList.Count == 0)
  123. {
  124. DoTargetList = false;
  125. TargetListTargetClean = false;
  126. return;
  127. }
  128. }
  129. else return;
  130. }
  131. if (DoTargetList)//Semi-auto | mouse pickup
  132. {
  133. ProcessTargetList();
  134. return;
  135. }
  136. if (Target == null)
  137. {
  138. shortcheck = true;
  139. FindTarget();
  140. }
  141. if (Target == null) ProcessAI();
  142. else ProcessTarget();
  143. ProcessRegen();
  144. }
  145. public void ProcessAnimVariant()
  146. {
  147. if (Envir.Time > AnimvariantTicker)
  148. {
  149. AnimvariantTicker = Envir.Time + AnimvariantDelay;
  150. ActionTime = Envir.Time + 300;
  151. AttackTime = Envir.Time + AttackSpeed;
  152. switch (PetType)
  153. {
  154. case IntelligentCreatureType.BabyDragon:
  155. case IntelligentCreatureType.OlympicFlame:
  156. if (Envir.Random.Next(10) > 5)
  157. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  158. else
  159. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 2 });
  160. break;
  161. case IntelligentCreatureType.BabySnowMan:
  162. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  163. break;
  164. default:
  165. switch(Envir.Random.Next(10))
  166. {
  167. case 0:
  168. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  169. break;
  170. case 1:
  171. case 2:
  172. case 3:
  173. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 1 });
  174. break;
  175. case 4:
  176. case 5:
  177. case 6:
  178. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 2 });
  179. break;
  180. case 7:
  181. case 8:
  182. case 9:
  183. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation, Type = 3 });
  184. break;
  185. }
  186. break;
  187. }
  188. }
  189. }
  190. public void ProcessBuffs()
  191. {
  192. //bool refresh = false;
  193. //if (refresh) RefreshAll();
  194. }
  195. protected override void ProcessAI()
  196. {
  197. if (Dead) return;
  198. if (Master != null)
  199. {
  200. if ((Master.PMode == PetMode.Both || Master.PMode == PetMode.MoveOnly))
  201. {
  202. if (!Functions.InRange(CurrentLocation, Master.CurrentLocation, Globals.DataRange) || CurrentMap != Master.CurrentMap)
  203. {
  204. Target = null;
  205. PetRecall();
  206. }
  207. }
  208. }
  209. if (Target == null)
  210. {
  211. shortcheck = true;
  212. FindTarget();
  213. }
  214. if (Target == null)
  215. {
  216. ProcessSearch();
  217. ProcessRoam();
  218. }
  219. ProcessTarget();
  220. }
  221. protected override void ProcessSearch()
  222. {
  223. if (Target == null)
  224. {
  225. shortcheck = true;
  226. FindTarget();
  227. }
  228. if (Target != null) return;
  229. if (Envir.Time < SearchTime) return;
  230. SearchTime = Envir.Time + SearchDelay;
  231. if (Target == null || Envir.Random.Next(3) == 0) FindTarget();
  232. }
  233. protected override void ProcessRoam()
  234. {
  235. if (Target == null) FindTarget();
  236. if (Target != null || Envir.Time < RoamTime) return;
  237. //if (ProcessRoute()) return;
  238. RoamTime = Envir.Time + 500;
  239. if (Master != null)
  240. {
  241. if (!Functions.InRange(CurrentLocation, Master.CurrentLocation, 2))
  242. MoveTo(Functions.PointMove(Master.CurrentLocation,Master.Direction, -2));
  243. else
  244. if (Envir.Random.Next(100) >= 60) ProcessAnimVariant();//random anims
  245. }
  246. }
  247. protected override void ProcessTarget()
  248. {
  249. if (Target == null || !CanAttack) return;
  250. if (Target.CurrentLocation == CurrentLocation || (!CheckAndMoveTo(Target.CurrentLocation) && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1)))
  251. {
  252. Attack();
  253. if (Target == null)
  254. {
  255. shortcheck = true;
  256. FindTarget();
  257. }
  258. return;
  259. }
  260. }
  261. protected override void FindTarget()
  262. {
  263. if (Dead) return;
  264. if (Fullness < CreatureRules.MinimalFullness) return;
  265. //do automatic pickup/find
  266. if (CreatureRules.AutoPickupEnabled && CurrentPickupMode == IntelligentCreaturePickupMode.Automatic)
  267. {
  268. FindItemTarget();
  269. }
  270. }
  271. private void FindItemTarget()
  272. {
  273. if (Master == null) return;
  274. int range = shortcheck ? 4 : CreatureRules.AutoPickupRange;
  275. for (int d = 0; d <= range; d++)
  276. {
  277. for (int y = CurrentLocation.Y - d; y <= CurrentLocation.Y + d; y++)
  278. {
  279. if (y < 0) continue;
  280. if (y >= CurrentMap.Height) break;
  281. for (int x = CurrentLocation.X - d; x <= CurrentLocation.X + d; x += Math.Abs(y - CurrentLocation.Y) == d ? 1 : d * 2)
  282. {
  283. if (x < 0) continue;
  284. if (x >= CurrentMap.Width) break;
  285. Cell cell = CurrentMap.GetCell(x, y);
  286. if (!cell.Valid || cell.Objects == null) continue;
  287. for (int i = 0; i < cell.Objects.Count; i++)
  288. {
  289. MapObject ob = cell.Objects[i];
  290. if (ob == null) continue;
  291. if (ob.Race != ObjectType.Item) continue;
  292. if (ob.Owner != null && ob.Owner != this && ob.Owner != Master && !IsMasterGroupMember(ob.Owner)) continue;
  293. ItemObject item = (ItemObject)ob;
  294. if (item.Item != null)
  295. {
  296. if (!((PlayerObject)Master).CanGainItem(item.Item)) continue;
  297. if (CheckItemAgainstFilter(item.Item.Info.Type))
  298. {
  299. //Master.ReceiveChat("YEAH ITEM I CAN GAIN {" + item.Item.FriendlyName + "} " + item.Item.Info.Type.ToString(), ChatType.System);
  300. if (item.Item.Info.Grade >= ItemFilter.PickupGrade)
  301. Target = ob;
  302. shortcheck = false;
  303. return;
  304. }
  305. }
  306. else
  307. {
  308. if (item.Gold > 0)
  309. {
  310. if (!((PlayerObject)Master).CanGainGold(item.Gold)) continue;
  311. if (ItemFilter.PetPickupAll || ItemFilter.PetPickupGold)
  312. {
  313. //Master.ReceiveChat("YEAH GOLD I CAN GAIN {" + item.Gold + "}", ChatType.System);
  314. Target = ob;
  315. shortcheck = false;
  316. return;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. shortcheck = false;
  325. }
  326. private bool FillTargetList(Point location)
  327. {
  328. int range = CreatureRules.SemiAutoPickupRange;
  329. TargetList.Clear();
  330. for (int d = 0; d <= range; d++)
  331. {
  332. for (int y = location.Y - d; y <= location.Y + d; y++)
  333. {
  334. if (y < 0) continue;
  335. if (y >= CurrentMap.Height) break;
  336. for (int x = location.X - d; x <= location.X + d; x += Math.Abs(y - location.Y) == d ? 1 : d * 2)
  337. {
  338. if (x < 0) continue;
  339. if (x >= CurrentMap.Width) break;
  340. Cell cell = CurrentMap.GetCell(x, y);
  341. if (!cell.Valid || cell.Objects == null) continue;
  342. for (int i = 0; i < cell.Objects.Count; i++)
  343. {
  344. MapObject ob = cell.Objects[i];
  345. if (ob == null) continue;
  346. if (ob.Race != ObjectType.Item) continue;
  347. if (ob.Owner != null && ob.Owner != this && ob.Owner != Master && !IsMasterGroupMember(ob.Owner)) continue;
  348. ItemObject item = (ItemObject)ob;
  349. if (item.Item != null)
  350. {
  351. if (!((PlayerObject)Master).CanGainItem(item.Item)) continue;
  352. if (CheckItemAgainstFilter(item.Item.Info.Type))
  353. {
  354. if(item.Item.Info.Grade >= ItemFilter.PickupGrade)
  355. TargetList.Add(ob);
  356. break;
  357. }
  358. }
  359. else
  360. {
  361. if (item.Gold > 0)
  362. {
  363. if (!((PlayerObject)Master).CanGainGold(item.Gold)) continue;
  364. if (ItemFilter.PetPickupAll || ItemFilter.PetPickupGold)
  365. {
  366. TargetList.Add(ob);
  367. break;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. }
  375. return (TargetList.Count > 0);
  376. }
  377. private void ProcessTargetList()
  378. {
  379. if (!DoTargetList) return;
  380. if (!CanAttack) return;
  381. if (TargetList.Count == 0)
  382. {
  383. DoTargetList = false;
  384. TargetListTargetClean = false;
  385. return;
  386. }
  387. bool remove = false;
  388. MapObject targ = TargetList[0];
  389. if (targ == null)
  390. remove = true;
  391. else
  392. {
  393. if (targ.CurrentMap != CurrentMap) remove = true;
  394. if (targ.Race != ObjectType.Item) remove = true;
  395. if (targ.Owner != null && targ.Owner != this && targ.Owner != Master && !IsMasterGroupMember(targ.Owner)) remove = true;
  396. }
  397. if (remove || TargetListTargetClean)
  398. {
  399. TargetList.RemoveAt(0);
  400. TargetListTargetClean = false;
  401. ProcessTargetList();//retry
  402. return;
  403. }
  404. Target = targ;
  405. if (Target.CurrentLocation == CurrentLocation || (!CheckAndMoveTo(Target.CurrentLocation) && Functions.InRange(CurrentLocation, Target.CurrentLocation, 1)))
  406. {
  407. DelayedAttack(500);
  408. if (Target == null)
  409. {
  410. TargetList.RemoveAt(0);
  411. if (TargetList.Count == 0)
  412. {
  413. DoTargetList = false;
  414. TargetListTargetClean = false;
  415. return;
  416. }
  417. }
  418. return;
  419. }
  420. }
  421. private bool CheckAndMoveTo(Point location)
  422. {
  423. if (CurrentLocation == location) return true;
  424. bool inRange = Functions.InRange(location, CurrentLocation, 1);
  425. if (inRange)
  426. {
  427. if (!CurrentMap.ValidPoint(location)) return false;
  428. Cell cell = CurrentMap.GetCell(location);
  429. if (cell.Objects != null)
  430. for (int i = 0; i < cell.Objects.Count; i++)
  431. {
  432. MapObject ob = cell.Objects[i];
  433. if (!ob.Blocking) continue;
  434. return false;
  435. }
  436. }
  437. MirDirection dir = Functions.DirectionFromPoint(CurrentLocation, location);
  438. if (Walk(dir)) return true;
  439. switch (Envir.Random.Next(2)) //No favour
  440. {
  441. case 0:
  442. for (int i = 0; i < 7; i++)
  443. {
  444. dir = Functions.NextDir(dir);
  445. if (Walk(dir)) return true;
  446. }
  447. break;
  448. default:
  449. for (int i = 0; i < 7; i++)
  450. {
  451. dir = Functions.PreviousDir(dir);
  452. if (Walk(dir)) return true;
  453. }
  454. break;
  455. }
  456. return false;
  457. }
  458. protected override void Attack()
  459. {
  460. bool singleitem = CurrentPickupMode == IntelligentCreaturePickupMode.SemiAutomatic ? true : false;
  461. PickupAllItems(Target.CurrentLocation);
  462. if (Target.CurrentLocation != CurrentLocation)
  463. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  464. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  465. Target = null;
  466. ActionTime = Envir.Time + 300;
  467. AttackTime = Envir.Time + AttackSpeed;
  468. DecreaseFullness(1);//use some food for operation
  469. IncreasePearlProduction();
  470. }
  471. private bool DelayedAttack(long delay)
  472. {
  473. DelayedPickup(delay);
  474. if (Target.CurrentLocation != CurrentLocation)
  475. Direction = Functions.DirectionFromPoint(CurrentLocation, Target.CurrentLocation);
  476. Broadcast(new S.ObjectAttack { ObjectID = ObjectID, Direction = Direction, Location = CurrentLocation });
  477. ActionTime = Envir.Time + 300;
  478. AttackTime = Envir.Time + AttackSpeed;
  479. DecreaseFullness(1);//use some food for operation
  480. IncreasePearlProduction();
  481. return true;
  482. }
  483. public void DelayedPickup(long delay)
  484. {
  485. DelayedpickupTicker = Envir.Time + delay;
  486. DoDelayedPickup = true;
  487. }
  488. public void PickupAllItems(Point location)
  489. {
  490. if (Dead || Master == null) return;
  491. if (!CurrentMap.ValidPoint(location)) return;
  492. Cell cell = CurrentMap.GetCell(location);
  493. if (cell.Objects == null) return;
  494. int count = cell.Objects.Count;
  495. for (int i = 0; i < count; i++)
  496. {
  497. PickUpItem(location);
  498. }
  499. }
  500. public void PickUpItem(Point location)
  501. {
  502. if (Dead || Master == null) return;
  503. if (!CurrentMap.ValidPoint(location)) return;
  504. Cell cell = CurrentMap.GetCell(location);
  505. if (cell.Objects == null) return;
  506. for (int i = 0; i < cell.Objects.Count; i++)
  507. {
  508. MapObject ob = cell.Objects[i];
  509. if (ob == null) continue;
  510. if (ob.Race != ObjectType.Item) continue;
  511. if (ob.Owner != null && ob.Owner != this && ob.Owner != Master && !IsMasterGroupMember(ob.Owner)) continue;
  512. ItemObject item = (ItemObject)ob;
  513. if (item == null) continue;
  514. if (item.Item != null)
  515. {
  516. if (!((PlayerObject)Master).CanGainItem(item.Item)) continue;
  517. if (item.Item.Info.ShowGroupPickup && IsMasterGroupMember(Master))
  518. for (int j = 0; j < Master.GroupMembers.Count; j++)
  519. Master.GroupMembers[j].ReceiveChat(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.FriendlyPickedUpItem), Name, item.Item.FriendlyName), ChatType.Hint);
  520. if (item.Item.Info.Grade == ItemGrade.Mythical || item.Item.Info.Grade == ItemGrade.Legendary || item.Item.Info.Grade == ItemGrade.Heroic)
  521. {
  522. Master.ReceiveChat(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.PetPickedUp), item.Item.FriendlyName), ChatType.Hint);
  523. ((PlayerObject)Master).Enqueue(new S.IntelligentCreaturePickup { ObjectID = ObjectID });
  524. }
  525. ((PlayerObject)Master).GainItem(item.Item);
  526. CurrentMap.RemoveObject(ob);
  527. ob.Despawn();
  528. return;
  529. }
  530. else
  531. {
  532. if (ob == null) continue;
  533. if (!((PlayerObject)Master).CanGainGold(item.Gold)) continue;
  534. ((PlayerObject)Master).GainGold(item.Gold);
  535. CurrentMap.RemoveObject(ob);
  536. ob.Despawn();
  537. return;
  538. }
  539. }
  540. }
  541. private bool CheckItemAgainstFilter(ItemType iType)
  542. {
  543. //dont use this method to check for gold.
  544. //instaid just do a simple check like -->> if (ItemFilter.PetPickupAll || ItemFilter.PetPickupGold)
  545. if (ItemFilter.PetPickupAll) return true;
  546. switch (iType)
  547. {
  548. case ItemType.Nothing:// <---- im not sure if any item will ever hold this ItemType but better to prevent then cure
  549. return false;
  550. case ItemType.Weapon:
  551. return ItemFilter.PetPickupWeapons;
  552. case ItemType.Armour:
  553. return ItemFilter.PetPickupArmours;
  554. case ItemType.Helmet:
  555. return ItemFilter.PetPickupHelmets;
  556. case ItemType.Boots:
  557. return ItemFilter.PetPickupBoots;
  558. case ItemType.Belt:
  559. return ItemFilter.PetPickupBelts;
  560. case ItemType.Necklace:
  561. case ItemType.Bracelet:
  562. case ItemType.Ring:
  563. return ItemFilter.PetPickupAccessories;
  564. default:
  565. return ItemFilter.PetPickupOthers;
  566. }
  567. }
  568. public void ManualPickup(bool mousemode, Point atLocation)
  569. {
  570. if (Fullness < CreatureRules.MinimalFullness) return;
  571. if (CreatureRules.MousePickupEnabled && mousemode)
  572. {
  573. FillTargetList(atLocation);
  574. DoTargetList = true;
  575. return;
  576. }
  577. if (!mousemode && CreatureRules.SemiAutoPickupEnabled && CurrentPickupMode == IntelligentCreaturePickupMode.SemiAutomatic)
  578. {
  579. FillTargetList(CurrentLocation);
  580. DoTargetList = true;
  581. return;
  582. }
  583. }
  584. public void IncreaseFullness(int amount)
  585. {
  586. if (Fullness >= 10000) return;
  587. FullnessTicker = Envir.Time + FullnessDelay;
  588. Fullness += amount;
  589. if (Fullness < CreatureRules.MinimalFullness) CreatureSay(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.PetHmmm));
  590. else CreatureSay(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.PetBurp));
  591. if (Fullness > 10000) Fullness = 10000;
  592. }
  593. public void DecreaseFullness(int amount)
  594. {
  595. if (Fullness <= 0 || MaintainfoodTime > 0) return;
  596. if (Envir.Time > FullnessTicker)
  597. {
  598. FullnessTicker = Envir.Time + FullnessDelay;
  599. Fullness -= amount;
  600. if (Fullness < 0) Fullness = 0;
  601. if (Fullness < CreatureRules.MinimalFullness) CreatureTimedSay(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.PetHungry));
  602. }
  603. }
  604. public void IncreasePearlProduction()
  605. {
  606. PearlTicker++;
  607. if (PearlTicker >= PearlProduceCount)
  608. {
  609. if (Master != null)
  610. {
  611. ((PlayerObject)Master).IntelligentCreatureProducePearl();
  612. }
  613. PearlTicker = 0;
  614. }
  615. }
  616. public void ProcessBlackStoneProduction()
  617. {
  618. if (!CreatureRules.CanProduceBlackStone) return;
  619. BlackstoneTime++;
  620. if (BlackstoneTime >= BlackstoneProduceTime)
  621. {
  622. if (Master != null)
  623. {
  624. ((PlayerObject)Master).IntelligentCreatureProduceBlackStone();
  625. }
  626. BlackstoneTime = 0;
  627. }
  628. }
  629. public void ProcessMaintainFoodBuff()
  630. {
  631. if (MaintainfoodTime > 0)
  632. {
  633. MaintainfoodTime--;
  634. if (MaintainfoodTime < 0)
  635. {
  636. MaintainfoodTime = 0;
  637. }
  638. }
  639. }
  640. public void CreatureTimedSay(string message)
  641. {
  642. if (Envir.Time > TimedSayTicker)
  643. {
  644. CreatureSay(message);
  645. TimedSayTicker = Envir.Time + TimedSayDelay;
  646. }
  647. }
  648. public void CreatureSay(string message)
  649. {
  650. if (Master != null)
  651. {
  652. message = String.Format("{0}:{1}", CustomName, message);
  653. ((PlayerObject)Master).IntelligentCreatureSay(PetType, message);
  654. }
  655. }
  656. public override void ReceiveChat(string text, ChatType type)
  657. {
  658. if (type == ChatType.WhisperIn) CreatureSay(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.PetWhat));
  659. }
  660. public override bool IsAttackTarget(HumanObject attacker)
  661. {
  662. return false;
  663. }
  664. public override bool IsAttackTarget(MonsterObject attacker)
  665. {
  666. return false;
  667. }
  668. public override bool IsFriendlyTarget(HumanObject ally)
  669. {
  670. return true;
  671. }
  672. public override bool IsFriendlyTarget(MonsterObject ally)
  673. {
  674. return true;
  675. }
  676. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  677. {
  678. return 0;
  679. }
  680. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  681. {
  682. return 0;
  683. }
  684. public override int Struck(int damage, DefenceType type = DefenceType.ACAgility)
  685. {
  686. return 0;
  687. }
  688. public override void ApplyPoison(Poison p, MapObject Caster = null, bool NoResist = false, bool ignoreDefence = true)
  689. {
  690. //FindTarget();
  691. }
  692. private bool IsMasterGroupMember(MapObject player)
  693. {
  694. if (player.Race != ObjectType.Player || Master == null) return false;
  695. return ((PlayerObject)Master).GroupMembers != null && ((PlayerObject)Master).GroupMembers.Contains((PlayerObject)player);
  696. }
  697. public override void Spawned()
  698. {
  699. base.Spawned();
  700. Summoned = true;
  701. FullnessTicker = Envir.Time + FullnessDelay;
  702. AnimvariantTicker = Envir.Time + AnimvariantDelay;
  703. }
  704. public override void Die()
  705. {
  706. if (Dead) return;
  707. base.Die();
  708. if (Dead)
  709. {
  710. CurrentMap.RemoveObject(this);
  711. Despawn();
  712. return;
  713. }
  714. }
  715. public override Packet GetInfo()
  716. {
  717. var packet=(S.ObjectMonster)base.GetInfo();
  718. packet.Extra = Summoned;
  719. return packet;
  720. }
  721. }
  722. }