-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTheLunaticPlayer.cs
165 lines (127 loc) · 4.26 KB
/
TheLunaticPlayer.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using HamstarHelpers.Classes.Errors;
using HamstarHelpers.Helpers.Debug;
using HamstarHelpers.Helpers.Players;
using Microsoft.Xna.Framework.Graphics;
using PlayerExtend;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
using TheLunatic.Buffs;
using TheLunatic.Items;
namespace TheLunatic {
partial class TheLunaticPlayer : ModPlayer {
public IDictionary<string, bool> Bye { get; private set; }
public PlayerNoclip Noclip { get; private set; }
public bool HasVerifiedGameData { get; private set; }
public bool IsInDangerZone { get; private set; }
private float QuakeScale = 1f;
private int QuakeDuration = 0;
private int QuakeStartDuration = 0;
public Texture2D MaskTex = null;
////////////////
public override bool CloneNewInstances => false;
public override void Initialize() {
this.Noclip = new PlayerNoclip();
this.Bye = new Dictionary<string, bool>();
this.HasVerifiedGameData = false;
this.IsInDangerZone = false;
}
public override void clientClone( ModPlayer clone ) {
var myclone = (TheLunaticPlayer)clone;
myclone.Bye = this.Bye;
myclone.Noclip = this.Noclip;
myclone.HasVerifiedGameData = this.HasVerifiedGameData;
myclone.QuakeScale = this.QuakeScale;
myclone.QuakeDuration = this.QuakeDuration;
myclone.QuakeStartDuration = this.QuakeStartDuration;
myclone.MaskTex = this.MaskTex;
}
////////////////
public override void SyncPlayer( int toWho, int fromWho, bool newPlayer ) {
var mymod = (TheLunaticMod)this.mod;
if( Main.netMode == 2 ) {
if( toWho == -1 && fromWho == this.player.whoAmI ) {
this.OnServerConnect( this.player );
}
}
}
public override void OnEnterWorld( Player enteringPlayer ) {
if( enteringPlayer.whoAmI != Main.myPlayer ) { return; }
if( this.player.whoAmI != Main.myPlayer ) { return; }
var mymod = (TheLunaticMod)this.mod;
if( mymod.Config.DebugModeInfo ) {
LogHelpers.Alert( enteringPlayer.name + " joined (" + PlayerIdentityHelpers.GetUniqueId( enteringPlayer ) + ")" );
}
if( Main.netMode == 0 ) {
this.OnSingleConnect();
}
if( Main.netMode == 1 ) {
this.OnClientConnect( enteringPlayer );
}
}
////////////////
public override void Load( TagCompound tags ) {
var mymod = (TheLunaticMod)this.mod;
try {
int worlds = tags.GetInt( "world_count" );
this.Bye = new Dictionary<string, bool>();
for( int i = 0; i < worlds; i++ ) {
string worldId = tags.GetString( "world_id_" + i );
this.Bye[worldId] = tags.GetBool( "bye_" + i );
}
if( mymod.Config.DebugModeInfo ) {
LogHelpers.Log( "DEBUG Load player. {" +
string.Join( ";", this.Bye.Select( x => x.Key + "=" + x.Value ).ToArray() ) + "}" );
}
} catch( Exception e ) {
LogHelpers.Log( e.ToString() );
}
}
public override TagCompound Save() {
var mymod = (TheLunaticMod)this.mod;
var tags = new TagCompound { { "world_count", this.Bye.Count } };
int i = 0;
foreach( var kv in this.Bye ) {
string worldId = kv.Key;
tags.Set( "world_id_" + i, worldId );
tags.Set( "bye_" + i, this.Bye[worldId] );
i++;
}
if( mymod.Config.DebugModeInfo ) {
LogHelpers.Log( "DEBUG Save player. {" +
string.Join( ";", this.Bye.Select( x => x.Key + "=" + x.Value ).ToArray() ) + "}" );
}
return tags;
}
////////////////
public override bool PreItemCheck() {
var mymod = (TheLunaticMod)this.mod;
if( !mymod.Config.Enabled ) { base.PreItemCheck(); }
try {
// Force de-select of items while shadow walking
if( this.player.HeldItem != null && this.player.HeldItem.type > 0 ) {
var buff = (ShadowWalkerBuff)mymod.GetBuff( "ShadowWalkerBuff" );
buff.PlayerPreItemCheck( this.player );
}
UmbralCowlItem.CheckEquipState( this.player );
} catch( Exception e ) {
throw new ModHelpersException( "", e );
}
return base.PreItemCheck();
}
////////////////
public bool IsCheater() {
var myworld = ModContent.GetInstance<TheLunaticWorld>();
if( !this.Bye.Keys.Contains( myworld.ID ) ) { return false; }
return this.Bye[myworld.ID];
}
////////////////
public void SetCheater() {
var myworld = ModContent.GetInstance<TheLunaticWorld>();
this.Bye[myworld.ID] = true;
}
}
}