Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
less warning
Browse files Browse the repository at this point in the history
nullable failures, need to be failed
  • Loading branch information
SlejmUr committed Feb 28, 2024
1 parent a9419f9 commit 55f2ce8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
67 changes: 43 additions & 24 deletions ServerLib/Controllers/MoveActionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MoveActionController
{ "Tag", TagItem },
{ "Toggle", ToggleItem },
{ "ApplyInventoryChanges", ApplyInventory },
{ "template", Template },
//{ "template", Template },
};

public static ProfileChanges CreateNew()
Expand All @@ -38,7 +38,7 @@ public static ProfileChanges CreateNew()
warnings = new()
};
}

/*
public static ProfileChanges Template(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Examine examineAction = action.ToObject<Inventory.Examine>();
Expand All @@ -57,6 +57,7 @@ public static ProfileChanges Template(string SessionId, ProfileChanges changes,
SaveHandler.SaveScav(SessionId, character);
return changes;
}
*/

public static ProfileChanges CreateBasicChanges(ProfileChanges changes, string SessionId)
{
Expand Down Expand Up @@ -86,7 +87,8 @@ public static ProfileChanges CreateBasicChanges(ProfileChanges changes, string S

public static ProfileChanges MoveItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Move moveAction = action.ToObject<Inventory.Move>();
Inventory.Move? moveAction = action.ToObject<Inventory.Move>();
ArgumentNullException.ThrowIfNull(moveAction, nameof(moveAction));
if (changes.warnings.Count > 0)
return changes;

Expand All @@ -113,13 +115,14 @@ public static ProfileChanges MoveItem(string SessionId, ProfileChanges changes,
}
else
{
item.Location = null;
item.Location = new();
}
ownerInventoryAction.To.Add(item);
ownerInventoryAction.From.Remove(FromItemSave);
}

CharacterController.TryGetCharacter(ownerInventoryAction.FromId, out var FromChar);
ArgumentNullException.ThrowIfNull(FromChar, nameof(FromChar));
FromChar.Inventory.Items = ownerInventoryAction.From;
string id = CharacterController.GetCharacterSessionId(FromChar);
if (id == string.Empty)
Expand All @@ -129,6 +132,7 @@ public static ProfileChanges MoveItem(string SessionId, ProfileChanges changes,
else
SaveHandler.SaveCharacter(id, FromChar);
CharacterController.TryGetCharacter(ownerInventoryAction.ToId, out var ToChar);
ArgumentNullException.ThrowIfNull(ToChar, nameof(ToChar));
ToChar.Inventory.Items = ownerInventoryAction.To;
if (CharacterController.IsCharacterScav(ToChar))
SaveHandler.SaveScav(SessionId, ToChar);
Expand All @@ -155,9 +159,10 @@ public static ProfileChanges MoveItem(string SessionId, ProfileChanges changes,
}
else
{
item.Location = null;
item.Location = new();
}
CharacterController.TryGetCharacter(ownerInventoryAction.FromId, out var FromChar);
ArgumentNullException.ThrowIfNull(FromChar, nameof(FromChar));
FromChar.Inventory.Items = ownerInventoryAction.From;
if (CharacterController.IsCharacterScav(FromChar))
SaveHandler.SaveScav(SessionId, FromChar);
Expand All @@ -169,16 +174,18 @@ public static ProfileChanges MoveItem(string SessionId, ProfileChanges changes,

public static ProfileChanges FoldItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Fold foldAction = action.ToObject<Inventory.Fold>();
Inventory.Fold? foldAction = action.ToObject<Inventory.Fold>();
ArgumentNullException.ThrowIfNull(foldAction, nameof(foldAction));
bool IsScav = false;
var character = CharacterController.GetPmcCharacter(SessionId);
if (foldAction.fromOwner != null && foldAction.fromOwner.type.ToLower() == "profile")
{
character = CharacterController.GetScavCharacter(SessionId);
IsScav = true;
}
ArgumentNullException.ThrowIfNull(character, nameof(character));
var item = character.Inventory.Items.Find(x => x.Id == foldAction.item);

ArgumentNullException.ThrowIfNull(item, nameof(item));
item.Upd.Foldable.Folded = foldAction.value;

if (!IsScav)
Expand All @@ -190,9 +197,10 @@ public static ProfileChanges FoldItem(string SessionId, ProfileChanges changes,

public static ProfileChanges ExamineItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Examine examineAction = action.ToObject<Inventory.Examine>();
Inventory.Examine? examineAction = action.ToObject<Inventory.Examine>();
ArgumentNullException.ThrowIfNull(examineAction, nameof(examineAction));
bool IsScav = false;
TemplateItem.Base templateItem = null;
TemplateItem.Base? templateItem = null;
var character = CharacterController.GetPmcCharacter(SessionId);
if (examineAction.fromOwner != null && examineAction.fromOwner.type.ToLower() == "profile")
{
Expand All @@ -205,6 +213,7 @@ public static ProfileChanges ExamineItem(string SessionId, ProfileChanges change
{
case "trader":
var assortItem = TraderController.GetAssortItemByID(examineAction.fromOwner.id, examineAction.item);
ArgumentNullException.ThrowIfNull(assortItem, nameof(assortItem));
templateItem = ItemController.Get(assortItem.Tpl);
break;
case "hideoutupgrade":
Expand All @@ -219,12 +228,13 @@ public static ProfileChanges ExamineItem(string SessionId, ProfileChanges change
}

}
ArgumentNullException.ThrowIfNull(character, nameof(character));
var item = character.Inventory.Items.Find(x => x.Id == examineAction.item);
if (item != null && templateItem == null)
{
templateItem = ItemController.Get(item.Tpl);
}

ArgumentNullException.ThrowIfNull(templateItem, nameof(templateItem));
character.Encyclopedia.Add(templateItem._id,true);
character.Info.Experience += (int)templateItem._props.ExamineExperience;

Expand All @@ -237,7 +247,8 @@ public static ProfileChanges ExamineItem(string SessionId, ProfileChanges change

public static ProfileChanges RemoveItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Remove removeAction = action.ToObject<Inventory.Remove>();
Inventory.Remove? removeAction = action.ToObject<Inventory.Remove>();
ArgumentNullException.ThrowIfNull(removeAction, nameof(removeAction));
bool IsScav = false;
var character = CharacterController.GetPmcCharacter(SessionId);
if (removeAction.fromOwner != null && removeAction.fromOwner.type.ToLower() == "profile")
Expand All @@ -256,7 +267,7 @@ public static ProfileChanges RemoveItem(string SessionId, ProfileChanges changes
{
Debug.PrintWarn("ProfileChanges not exist?", "RemoveItem.WARN");
}

ArgumentNullException.ThrowIfNull(character, nameof(character));
var toRemoveItems = InventoryController.GetInventoryItemFamilyTreeIDs(character.Inventory.Items, removeAction.item);

foreach (var item in toRemoveItems)
Expand All @@ -282,8 +293,8 @@ public static ProfileChanges RemoveItem(string SessionId, ProfileChanges changes

public static ProfileChanges SplitItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Split splitAction = action.ToObject<Inventory.Split>();

Inventory.Split? splitAction = action.ToObject<Inventory.Split>();
ArgumentNullException.ThrowIfNull(splitAction, nameof(splitAction));
var ownerInventory = GetOwnerInventoryAction(SessionId, splitAction);
var item = ownerInventory.From.Where(x => x.Id == splitAction.item).FirstOrDefault();
if (item == null)
Expand Down Expand Up @@ -335,26 +346,27 @@ public static ProfileChanges AddWarning(ProfileChanges changes, string message,

public static ProfileChanges SwapItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Swap swapAction = action.ToObject<Inventory.Swap>();
Inventory.Swap? swapAction = action.ToObject<Inventory.Swap>();
ArgumentNullException.ThrowIfNull(swapAction, nameof(swapAction));
bool IsScav = false;
TemplateItem.Base templateItem = null;
var character = CharacterController.GetPmcCharacter(SessionId);
if (swapAction.fromOwner != null && swapAction.fromOwner.type.ToLower() == "profile")
{
character = CharacterController.GetScavCharacter(SessionId);
IsScav = true;
}

ArgumentNullException.ThrowIfNull(character, nameof(character));
var swapItem = character.Inventory.Items.Find(x=>x.Id == swapAction.item);
var swapItem2 = character.Inventory.Items.Find(x => x.Id == swapAction.item2);

ArgumentNullException.ThrowIfNull(swapItem, nameof(swapItem));
ArgumentNullException.ThrowIfNull(swapItem2, nameof(swapItem2));
if (swapAction.to.location != null)
{
swapItem.Location = JsonHelper.FromActionLocation(swapAction.to.location);
}
else
{
swapItem.Location = null;
swapItem.Location = new();
}
swapItem.ParentId = swapAction.to.id;
swapItem.SlotId = swapAction.to.container;
Expand All @@ -365,7 +377,7 @@ public static ProfileChanges SwapItem(string SessionId, ProfileChanges changes,
}
else
{
swapItem2.Location = null;
swapItem2.Location = new();
}
swapItem2.ParentId = swapAction.to2.id;
swapItem2.SlotId = swapAction.to2.container;
Expand All @@ -380,19 +392,20 @@ public static ProfileChanges SwapItem(string SessionId, ProfileChanges changes,

public static ProfileChanges TransferItem(string SessionId, ProfileChanges changes, JObject action)
{
Inventory.Transfer transferAction = action.ToObject<Inventory.Transfer>();
Inventory.Transfer? transferAction = action.ToObject<Inventory.Transfer>();
ArgumentNullException.ThrowIfNull(transferAction, nameof(transferAction));
bool IsScav = false;
TemplateItem.Base templateItem = null;
var character = CharacterController.GetPmcCharacter(SessionId);
if (transferAction.fromOwner != null && transferAction.fromOwner.type.ToLower() == "profile")
{
character = CharacterController.GetScavCharacter(SessionId);
IsScav = true;
}

ArgumentNullException.ThrowIfNull(character, nameof(character));
var toMerge = character.Inventory.Items.Find(x=>x.Id == transferAction.item);
var mergeWith = character.Inventory.Items.Find(x => x.Id == transferAction.with);

ArgumentNullException.ThrowIfNull(toMerge, nameof(toMerge));
ArgumentNullException.ThrowIfNull(mergeWith, nameof(mergeWith));
toMerge.Upd.StackObjectsCount -= transferAction.count;
mergeWith.Upd.StackObjectsCount += transferAction.count;

Expand Down Expand Up @@ -586,6 +599,9 @@ public static OwnerInventoryAction GetOwnerInventoryAction(string SessionId, Bas
{
var pmc = CharacterController.GetPmcCharacter(SessionId);
var scav = CharacterController.GetScavCharacter(SessionId);
ArgumentNullException.ThrowIfNull(pmc, nameof(pmc));
ArgumentNullException.ThrowIfNull(scav, nameof(scav));

List<Item.Base> From = pmc.Inventory.Items;
string FromId = pmc.Id;
List<Item.Base> To = pmc.Inventory.Items;
Expand All @@ -608,6 +624,7 @@ public static OwnerInventoryAction GetOwnerInventoryAction(string SessionId, Bas
}
if (CharacterController.TryGetCharacter(SessionId, out var charbase))
{
ArgumentNullException.ThrowIfNull(charbase, nameof(charbase));
From = charbase.Inventory.Items;
FromId = charbase.Id;
fromType = "otherCharacter";
Expand Down Expand Up @@ -637,6 +654,7 @@ public static OwnerInventoryAction GetOwnerInventoryAction(string SessionId, Bas
public static void OwnerActionSaveProfiles(string SessionId, OwnerInventoryAction ownerInventoryAction)
{
CharacterController.TryGetCharacter(ownerInventoryAction.FromId, out var FromChar);
ArgumentNullException.ThrowIfNull(FromChar, nameof(FromChar));
FromChar.Inventory.Items = ownerInventoryAction.From;
string id = CharacterController.GetCharacterSessionId(FromChar);
if (id == string.Empty)
Expand All @@ -646,6 +664,7 @@ public static void OwnerActionSaveProfiles(string SessionId, OwnerInventoryActio
else
SaveHandler.SaveCharacter(id, FromChar);
CharacterController.TryGetCharacter(ownerInventoryAction.ToId, out var ToChar);
ArgumentNullException.ThrowIfNull(ToChar, nameof(ToChar));
ToChar.Inventory.Items = ownerInventoryAction.To;
if (CharacterController.IsCharacterScav(ToChar))
SaveHandler.SaveScav(SessionId, ToChar);
Expand Down
2 changes: 1 addition & 1 deletion TarkovServer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BundleSupport", "Plugins\Bu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StressTester", "StressTester\StressTester.csproj", "{FB282476-6C58-4EF9-8EDB-943865742AFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MTGAPlugin", "Plugins\MTGAPlugin\MTGAPlugin.csproj", "{1D4FDACF-A1DB-49FC-AE3E-56DCE7A1B839}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MTGAPlugin", "Plugins\MTGAPlugin\MTGAPlugin.csproj", "{1D4FDACF-A1DB-49FC-AE3E-56DCE7A1B839}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

0 comments on commit 55f2ce8

Please sign in to comment.