Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlayerData changes #2946

Open
wants to merge 5 commits into
base: general-devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TShockAPI/DB/CharacterManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public CharacterManager(IDbConnection db)

public PlayerData GetPlayerData(TSPlayer player, int acctid)
{
PlayerData playerData = new PlayerData(player);
PlayerData playerData = new PlayerData(false);

try
{
Expand Down
4 changes: 2 additions & 2 deletions TShockAPI/GetDataHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2619,9 +2619,9 @@ private static bool HandlePlayerSlot(GetDataHandlerArgs args)
private static bool HandleConnecting(GetDataHandlerArgs args)
{
var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name);//
args.Player.DataWhenJoined = new PlayerData(args.Player);
args.Player.DataWhenJoined = new PlayerData(false);
args.Player.DataWhenJoined.CopyCharacter(args.Player);
args.Player.PlayerData = new PlayerData(args.Player);
args.Player.PlayerData = new PlayerData(false);
args.Player.PlayerData.CopyCharacter(args.Player);

if (account != null && !TShock.Config.Settings.DisableUUIDLogin)
Expand Down
40 changes: 30 additions & 10 deletions TShockAPI/PlayerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU General Public License
using Terraria.GameContent.NetModules;
using Terraria.Net;
using Terraria.ID;
using System;

namespace TShockAPI
{
Expand Down Expand Up @@ -63,18 +64,27 @@ public class PlayerData
public int unlockedSuperCart;
public int enabledSuperCart;

public PlayerData(TSPlayer player)
/// <summary>
/// Sets the default values for the inventory.
/// </summary>
[Obsolete("The player argument is not used.")]
public PlayerData(TSPlayer player) : this(true) { }

/// <summary>
/// Sets the default values for the inventory.
/// </summary>
/// <param name="includingStarterInventory">Is it necessary to load items from TShock's config</param>
public PlayerData(bool includingStarterInventory = true)
{
for (int i = 0; i < NetItem.MaxInventory; i++)
{
this.inventory[i] = new NetItem();
}

for (int i = 0; i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count; i++)
{
var item = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i];
StoreSlot(i, item.NetId, item.PrefixId, item.Stack);
}
if (includingStarterInventory)
for (int i = 0; i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count; i++)
{
var item = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i];
StoreSlot(i, item.NetId, item.PrefixId, item.Stack);
}
}

/// <summary>
Expand All @@ -86,12 +96,22 @@ public PlayerData(TSPlayer player)
/// <param name="stack"></param>
public void StoreSlot(int slot, int netID, byte prefix, int stack)
{
if (slot > (this.inventory.Length - 1)) //if the slot is out of range then dont save
StoreSlot(slot, new NetItem(netID, stack, prefix));
}

/// <summary>
/// Stores an item at the specific storage slot
/// </summary>
/// <param name="slot"></param>
/// <param name="item"></param>
public void StoreSlot(int slot, NetItem item)
{
if (slot > (this.inventory.Length - 1) || slot < 0) //if the slot is out of range then dont save
{
return;
}

this.inventory[slot] = new NetItem(netID, stack, prefix);
this.inventory[slot] = item;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion TShockAPI/TSPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ public void Logout()
}
}

PlayerData = new PlayerData(this);
PlayerData = new PlayerData();
Group = TShock.Groups.GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName);
tempGroup = null;
if (tempGroupTimer != null)
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace)
* Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace)
* Fixed typo in `/gbuff`. (@sgkoishi, #2955)
* Added a constructor for `TShockAPI.PlayerData` that accepts the `includingStarterInventory` parameter, which is responsible for loading the TShock inventory.
* Declared the constructor `TShockAPI.PlayerData` accepting the argument `TShockAPI.TSPlayer` obsolete.
* Updated the `PlayerData.StoreSlot` method: Added an overload that takes `TShockAPI.NetItem`.

## TShock 5.2
* An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK)
Expand Down