writtennotedata.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. class WrittenNoteData
  2. {
  3. protected ItemBase m_WritingImplement;
  4. protected ItemBase m_Paper;
  5. //protected int m_Handwriting = -1;
  6. protected string m_SimpleText;
  7. void WrittenNoteData(ItemBase parent)
  8. {
  9. }
  10. void OnRPC( PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
  11. {
  12. Param1<string> param = new Param1<string>("");
  13. //sent from server, executed on client
  14. if (rpc_type == ERPCs.RPC_WRITE_NOTE)
  15. {
  16. if (ctx.Read(param))
  17. {
  18. SetNoteText(param.param1);
  19. }
  20. g_Game.GetMission().SetNoteMenu(g_Game.GetUIManager().EnterScriptedMenu(MENU_NOTE, GetGame().GetUIManager().GetMenu())); //NULL means no parent
  21. ItemBase pen;
  22. ItemBase paper;
  23. //int handwriting;
  24. if (GetNoteInfo(pen,paper))
  25. {
  26. g_Game.GetMission().GetNoteMenu().InitNoteWrite(paper,pen,m_SimpleText);
  27. }
  28. }
  29. //sent from client (NoteMenu), executed on server
  30. if (rpc_type == ERPCs.RPC_WRITE_NOTE_CLIENT)
  31. {
  32. if (ctx.Read(param))
  33. {
  34. string old_string = m_SimpleText;
  35. SetNoteText(param.param1);
  36. DepleteWritingImplement(m_WritingImplement,old_string,m_SimpleText);
  37. }
  38. }
  39. if (rpc_type == ERPCs.RPC_READ_NOTE)
  40. {
  41. if (ctx.Read(param))
  42. {
  43. SetNoteText(param.param1);
  44. }
  45. g_Game.GetMission().SetNoteMenu(g_Game.GetUIManager().EnterScriptedMenu(MENU_NOTE, GetGame().GetUIManager().GetMenu())); //NULL means no parent
  46. g_Game.GetMission().GetNoteMenu().InitNoteRead(m_SimpleText);
  47. }
  48. }
  49. void InitNoteInfo(ItemBase pen = null, ItemBase paper = null)
  50. {
  51. m_WritingImplement = pen;
  52. m_Paper = paper;
  53. //m_Handwriting = handwriting;
  54. }
  55. bool GetNoteInfo(out ItemBase pen, out ItemBase paper)
  56. {
  57. pen = m_WritingImplement;
  58. paper = m_Paper;
  59. //handwriting = m_Handwriting;
  60. return pen && paper;
  61. }
  62. string GetNoteText()
  63. {
  64. return m_SimpleText;
  65. }
  66. void SetNoteText(string text)
  67. {
  68. m_SimpleText = MiscGameplayFunctions.SanitizeString(text);
  69. }
  70. void DepleteWritingImplement(notnull ItemBase pen,string old_text,string new_text)
  71. {
  72. float qty_per_char = 1.0;
  73. float decrease = Math.Clamp((new_text.Length() - old_text.Length()),0,pen.GetQuantityMax());
  74. pen.AddQuantity(-(qty_per_char * decrease));
  75. }
  76. }
  77. //-----------------------