-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLivesPlayer.cs
129 lines (94 loc) · 3.02 KB
/
LivesPlayer.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
using HamstarHelpers.Helpers.Debug;
using System;
using Terraria;
using Terraria.DataStructures;
using Terraria.ModLoader;
using Terraria.ModLoader.IO;
namespace Lives {
partial class LivesPlayer : ModPlayer {
public int Lives { get; private set; }
public int Deaths { get; private set; }
public int ContinuesUsed { get; private set; }
public byte OriginalDifficulty { get; private set; }
public bool IsImmortal { get; private set; }
private bool IsLoaded = false;
////
public override bool CloneNewInstances => false;
////////////////
public override void Initialize() {
this.OriginalDifficulty = this.player.difficulty;
this.ResetLivesToDefault();
}
public override void clientClone( ModPlayer clone ) {
base.clientClone( clone );
var myclone = (LivesPlayer)clone;
myclone.IsImmortal = this.IsImmortal;
myclone.Lives = this.Lives;
myclone.Deaths = this.Deaths;
myclone.OriginalDifficulty = this.OriginalDifficulty;
}
////////////////
public override void SyncPlayer( int toWho, int fromWho, bool newPlayer ) {
var mymod = (LivesMod)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 = (LivesMod)this.mod;
if( Main.netMode == 0 ) {
this.OnSingleConnect();
}
if( Main.netMode == 1 ) {
this.OnCurrentClientConnect();
}
}
////////////////
public override void Load( TagCompound tags ) {
try {
if( tags.ContainsKey("lives") ) {
this.IsLoaded = true;
this.IsImmortal = tags.GetBool( "is_immortal" );
this.Lives = tags.GetInt( "lives" );
this.Deaths = tags.GetInt( "lives_lost" );
this.OriginalDifficulty = tags.GetByte( "difficulty" );
}
if( tags.ContainsKey("continues") ) {
this.ContinuesUsed = tags.GetInt( "continues" );
}
this.UpdateMortality();
} catch( Exception e ) {
LogHelpers.Log( e.ToString() );
}
}
public override TagCompound Save() {
var tags = new TagCompound {
{"is_immortal", this.IsImmortal},
{"lives", this.Lives},
{"lives_lost", this.Deaths},
{"difficulty", this.OriginalDifficulty},
{"continues", this.ContinuesUsed}
};
return tags;
}
////////////////
public override bool PreKill( double damage, int hitDirection, bool pvp, ref bool playSound, ref bool genGore, ref PlayerDeathReason damageSource ) {
if( !LivesConfig.Instance.Enabled ) {
base.PreKill( damage, hitDirection, pvp, ref playSound, ref genGore, ref damageSource );
}
this.DeathHappened( pvp );
return base.PreKill( damage, hitDirection, pvp, ref playSound, ref genGore, ref damageSource );
}
////////////////
public void ResetLivesToDefault() {
var mymod = (LivesMod)this.mod;
this.Lives = LivesConfig.Instance.InitialLives;
this.Deaths = 0;
this.IsImmortal = false;
}
}
}