source: binary-improvements/7dtd-server-fixes/src/PersistentData/Inventory.cs@ 252

Last change on this file since 252 was 251, checked in by peter.souza, 9 years ago

Enemies (zombies and hostile animal entities) are now shown on the map as Hostiles and require permission level 'webapi.gethostilelocation' for web viewers to see.

Animals (non-hostile entities) are now shown on the map as Animals and require permission level 'webapi.getanimalslocation' for web viewers to see.

Permission level for 'webapi.viewallclaims' is now required for a viewer to see all claims, otherwise the permission level for 'webapi.getlandclaims' will only show viewer-owned claims. A viewer requires both 'webapi.getlandclaims' and 'webapi.viewallclaims' to be set for all claims to show (you can't just set 'webapi.viewallclaims').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Permission level for 'webapi.viewallplayers' is now required for a viewer to see all players, otherwise the permission level for 'webapi.getplayerslocation' will only show the player for the currently-authenticated viewer. A viewer requires both 'webapi.getplayerslocation' and 'webapi.viewallplayers' to be set for all players to show (you can't just set 'webapi.viewallplayers').
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317405&viewfull=1#post317405

Banned players are now hidden from the web map.
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=320702&viewfull=1#post320702

Items using 'CustomIcon' and 'CustomIconTint' are now supported (although the exact tinting may not be perfectly the same as the game).
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317117&viewfull=1#post317117
https://7daystodie.com/forums/showthread.php?12837-Improvements-for-the-dedicated-server&p=317679&viewfull=1#post317679

Map marker icons for players, hostiles, and animals have been updated.

File size: 3.9 KB
RevLine 
[251]1using System;
2using System.Collections.Generic;
3using System.Runtime.Serialization;
4using System.Threading;
5
6namespace AllocsFixes.PersistentData
7{
8 [Serializable]
9 public class Inventory {
10 public List<InvItem> bag;
11 public List<InvItem> belt;
12 public InvItem[] equipment;
13
14 public Inventory () {
15 bag = new List<InvItem> ();
16 belt = new List<InvItem> ();
17 equipment = null;
18 }
19
20 public void Update (PlayerDataFile pdf) {
21 lock (this) {
22 //Log.Out ("Updating player inventory - player id: " + pdf.id);
23 ProcessInv (bag, pdf.bag, pdf.id);
24 ProcessInv (belt, pdf.inventory, pdf.id);
25 ProcessEqu (pdf.equipment, pdf.id);
26 }
27 }
28
29 private void ProcessInv (List<InvItem> target, ItemStack[] sourceFields, int id) {
30 target.Clear ();
31 for (int i = 0; i < sourceFields.Length; i++) {
32 InvItem item = CreateInvItem (sourceFields [i].itemValue, sourceFields [i].count, id);
33 if (item != null && sourceFields [i].itemValue.Parts != null) {
34 ProcessParts (sourceFields [i].itemValue.Parts, item, id);
35 }
36 target.Add (item);
37 }
38 }
39
40 private void ProcessEqu (Equipment sourceEquipment, int _playerId) {
41 equipment = new InvItem[sourceEquipment.GetSlotCount ()];
42 for (int i = 0; i < sourceEquipment.GetSlotCount (); i++) {
43 equipment [i] = CreateInvItem (sourceEquipment.GetSlotItem (i), 1, _playerId);
44 }
45 }
46
47 private void ProcessParts (ItemValue[] _parts, InvItem _item, int _playerId) {
48 InvItem[] itemParts = new InvItem[_parts.Length];
49 for (int i = 0; i < _parts.Length; i++) {
50 InvItem partItem = CreateInvItem (_parts [i], 1, _playerId);
51 if (partItem != null && _parts [i].Parts != null) {
52 ProcessParts (_parts [i].Parts, partItem, _playerId);
53 }
54 itemParts [i] = partItem;
55 }
56 _item.parts = itemParts;
57 }
58
59 private InvItem CreateInvItem (ItemValue _itemValue, int _count, int _playerId) {
60 if (_count > 0 && _itemValue != null && !_itemValue.Equals (ItemValue.None)) {
61 int maxAllowed = ItemClass.list [_itemValue.type].Stacknumber.Value;
62 string name = ItemClass.list [_itemValue.type].GetItemName ();
63
64 if (_count > maxAllowed) {
65 Log.Out ("Player with ID " + _playerId + " has stack for \"" + name + "\" greater than allowed (" + _count + " > " + maxAllowed + ")");
66 }
67
68 InvItem item = null;
69 if (_itemValue.HasQuality) {
70 item = new InvItem (name, _count, _itemValue.Quality);
71 } else {
72 item = new InvItem (name, _count);
73 }
74
75 // Figure out the icon's name
76 string icon_name = "";
77
78 ItemClass item_class = ItemClass.list [_itemValue.type];
79
80 if (!PetesUtils.ValidText (icon_name)) {
81 try {
82 icon_name = item_class.GetIconName ();
83 }
84 catch { }
85 }
86
87 if (!PetesUtils.ValidText (icon_name)) {
88 try {
89 icon_name = item_class.MeshFile;
90 }
91 catch { }
92 }
93
94 if (!PetesUtils.ValidText (icon_name)) {
95 try {
96 icon_name = item_class.DropMeshFile;
97 }
98 catch { }
99 }
100
101 if (!PetesUtils.ValidText (icon_name))
102 icon_name = item_class.GetItemName ();
103
104 if (icon_name.Contains ("\\"))
105 icon_name = icon_name.Substring (icon_name.LastIndexOf ("\"") + 1);
106
107 item.icon = icon_name;
108
109 try {
110 item.iconcolor = item_class.CustomIconTint.ToHexStringRGB ();
111 }
112 catch {
113 item.iconcolor = "FFFFFF";
114 }
115
116 return item;
117 } else {
118 return null;
119 }
120 }
121 }
122}
Note: See TracBrowser for help on using the repository browser.