mirror of
				https://bitbucket.org/Ioncannon/project-meteor-server.git
				synced 2025-05-20 08:26:59 -04:00 
			
		
		
		
	Refactored quest state system seems to work!
This commit is contained in:
		
							
								
								
									
										167
									
								
								Map Server/Actors/Quest/QuestData.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								Map Server/Actors/Quest/QuestData.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
|  | ||||
| namespace Meteor.Map.Actors.QuestNS | ||||
| { | ||||
|     class QuestData | ||||
|     { | ||||
|         private Player owner; | ||||
|         private Quest parent; | ||||
|  | ||||
|         private uint flags; | ||||
|         private ushort counter1; | ||||
|         private ushort counter2; | ||||
|         private ushort counter3; | ||||
|         private ushort counter4; | ||||
|         private bool dataDirty = false; | ||||
|  | ||||
|         public QuestData(Player owner, Quest parent, uint flags, ushort counter1, ushort counter2, ushort counter3, ushort counter4) | ||||
|         { | ||||
|             this.owner = owner; | ||||
|             this.parent = parent; | ||||
|             this.flags = flags; | ||||
|             this.counter1 = counter1; | ||||
|             this.counter2 = counter2; | ||||
|             this.counter3 = counter3; | ||||
|             this.counter4 = counter4; | ||||
|         } | ||||
|  | ||||
|         public QuestData(Player owner, Quest parent) | ||||
|         { | ||||
|             this.owner = owner; | ||||
|             this.parent = parent; | ||||
|             flags = counter1 = counter2 = counter3 = counter4 = 0; | ||||
|         } | ||||
|  | ||||
|         public void ClearData() | ||||
|         { | ||||
|             flags = counter1 = counter2 = counter3 = counter4 = 0; | ||||
|         } | ||||
|  | ||||
|         public void SetFlag(int index) | ||||
|         { | ||||
|             if (index >= 0 && index < 32) | ||||
|             { | ||||
|                 flags |= (uint)(1 << index); | ||||
|                 dataDirty = true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public void ClearFlag(int index) | ||||
|         { | ||||
|             if (index >= 0 && index < 32) | ||||
|             { | ||||
|                 flags &= (uint)~(1 << index); | ||||
|                 dataDirty = true; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public ushort IncCounter(int num) | ||||
|         { | ||||
|             dataDirty = true; | ||||
|  | ||||
|             switch (num) | ||||
|             { | ||||
|                 case 0: | ||||
|                     counter1++; | ||||
|                     return counter1; | ||||
|                 case 1: | ||||
|                     counter2++; | ||||
|                     return counter2; | ||||
|                 case 2: | ||||
|                     counter3++; | ||||
|                     return counter3; | ||||
|                 case 3: | ||||
|                     counter4++; | ||||
|                     return counter4; | ||||
|             } | ||||
|  | ||||
|             dataDirty = false; | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         public ushort DecCounter(int num) | ||||
|         { | ||||
|             dataDirty = true; | ||||
|  | ||||
|             switch (num) | ||||
|             { | ||||
|                 case 0: | ||||
|                     counter1--; | ||||
|                     return counter1; | ||||
|                 case 1: | ||||
|                     counter2--; | ||||
|                     return counter2; | ||||
|                 case 2: | ||||
|                     counter3--; | ||||
|                     return counter3; | ||||
|                 case 3: | ||||
|                     counter4--; | ||||
|                     return counter4; | ||||
|             } | ||||
|  | ||||
|             dataDirty = false; | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         public void SetCounter(int num, ushort value) | ||||
|         { | ||||
|             dataDirty = true; | ||||
|  | ||||
|             switch (num) | ||||
|             { | ||||
|                 case 0: | ||||
|                     counter1 = value; | ||||
|                     return; | ||||
|                 case 1: | ||||
|                     counter2 = value; | ||||
|                     return; | ||||
|                 case 2: | ||||
|                     counter3 = value; | ||||
|                     return; | ||||
|                 case 3: | ||||
|                     counter4 = value; | ||||
|                     return; | ||||
|             } | ||||
|  | ||||
|             dataDirty = false; | ||||
|         } | ||||
|  | ||||
|         public bool GetFlag(int index) | ||||
|         { | ||||
|             if (index >= 0 && index < 32) | ||||
|                 return (flags & (uint)(1 << index)) != 0; | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         public uint GetFlags() | ||||
|         { | ||||
|             return flags; | ||||
|         } | ||||
|  | ||||
|         public ushort GetCounter(int num) | ||||
|         { | ||||
|             switch (num) | ||||
|             { | ||||
|                 case 0: | ||||
|                     return counter1; | ||||
|                 case 1: | ||||
|                     return counter2; | ||||
|                 case 2: | ||||
|                     return counter3; | ||||
|                 case 3: | ||||
|                     return counter4; | ||||
|             } | ||||
|  | ||||
|             return 0; | ||||
|         } | ||||
|  | ||||
|         public void Save() | ||||
|         { | ||||
|             Database.SaveQuest(owner, parent); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user