-
Notifications
You must be signed in to change notification settings - Fork 0
/
CapitalismPlayer.cs
123 lines (90 loc) · 2.69 KB
/
CapitalismPlayer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using Terraria.ModLoader;
using Terraria;
using Terraria.ModLoader.IO;
using Capitalism.Logic;
using Capitalism.NetProtocol;
using HamstarHelpers.Services.Hooks.LoadHooks;
namespace Capitalism {
class CapitalismPlayer : ModPlayer {
private CapitalismLogic Logic;
////////////////
public override bool CloneNewInstances => false;
public override void Initialize() {
this.Logic = new CapitalismLogic();
}
public override void clientClone( ModPlayer clone ) {
base.clientClone( clone );
var myclone = (CapitalismPlayer)clone;
myclone.Logic = this.Logic;
}
////////////////
public override void SyncPlayer( int toWho, int fromWho, bool newPlayer ) {
var mymod = (CapitalismMod)this.mod;
if( Main.netMode == 2 ) {
if( toWho == -1 && fromWho == this.player.whoAmI ) {
this.OnServerConnect();
}
}
}
public override void OnEnterWorld( Player player ) {
if( player.whoAmI != Main.myPlayer ) { return; }
if( this.player.whoAmI != Main.myPlayer ) { return; }
var mymod = (CapitalismMod)this.mod;
if( Main.netMode == 0 ) {
this.OnSingleConnect();
}
if( Main.netMode == 1 ) {
this.OnClientConnect();
}
}
////////////////
private void OnSingleConnect() {
}
private void OnClientConnect() {
LoadHooks.AddWorldLoadOnceHook( () => {
WorldDataProtocol.QuickRequest();
} );
}
private void OnServerConnect() {
}
////////////////
public override void Load( TagCompound tags ) {
if( !tags.ContainsKey( "vendor_world_count" ) ) { return; }
var mymod = (CapitalismMod)this.mod;
int totalWorlds = tags.GetInt( "vendor_world_count" );
for( int i=0; i< totalWorlds; i++ ) {
string id = tags.GetString( "vendor_world_id_" + i );
this.Logic.LoadVendorsForCurrentPlayer( mymod, tags, id );
}
}
public override TagCompound Save() {
int world_count = this.Logic.VendorWorlds.Count;
var tags = new TagCompound { { "vendor_world_count", world_count } };
int i = 0;
foreach( string id in this.Logic.VendorWorlds.Keys ) {
tags.Set( "vendor_world_id_"+i, id );
i++;
}
this.Logic.SaveVendorsForCurrentPlayer( tags );
return tags;
}
////////////////
public override void PreUpdate() {
var mymod = (CapitalismMod)this.mod;
if( !mymod.Config.Enabled ) { return; }
this.Logic.Update( this.player );
}
////////////////
public void UpdateGivenShop( int npcType, Chest shop, ref int nextSlot ) {
if( this.Logic != null ) {
this.Logic.UpdateGivenShop( this.player, npcType, shop, ref nextSlot );
}
}
public bool InfuriateVendor( int npcType ) {
if( this.Logic != null ) {
return this.Logic.InfuriateVendor( npcType );
}
return false;
}
}
}