Syncing character skill levels
This commit is contained in:
@@ -715,7 +715,19 @@ namespace Barotrauma
|
|||||||
msg.Write(this is AICharacter);
|
msg.Write(this is AICharacter);
|
||||||
msg.Write(Info.Gender == Gender.Female);
|
msg.Write(Info.Gender == Gender.Female);
|
||||||
msg.Write((byte)Info.HeadSpriteId);
|
msg.Write((byte)Info.HeadSpriteId);
|
||||||
msg.Write(Info.Job == null ? "" : Info.Job.Name);
|
if (info.Job != null)
|
||||||
|
{
|
||||||
|
msg.Write(Info.Job.Name);
|
||||||
|
msg.Write((byte)info.Job.Skills.Count);
|
||||||
|
foreach (Skill skill in info.Job.Skills)
|
||||||
|
{
|
||||||
|
msg.WriteRangedInteger(0, 100, MathHelper.Clamp(skill.Level, 0, 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.Write("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Character ReadSpawnData(NetBuffer inc, bool spawn = true)
|
public static Character ReadSpawnData(NetBuffer inc, bool spawn = true)
|
||||||
@@ -746,22 +758,42 @@ namespace Barotrauma
|
|||||||
int ownerId = hasOwner ? inc.ReadByte() : -1;
|
int ownerId = hasOwner ? inc.ReadByte() : -1;
|
||||||
|
|
||||||
|
|
||||||
string newName = inc.ReadString();
|
string newName = inc.ReadString();
|
||||||
byte teamID = inc.ReadByte();
|
byte teamID = inc.ReadByte();
|
||||||
|
|
||||||
bool hasAi = inc.ReadBoolean();
|
bool hasAi = inc.ReadBoolean();
|
||||||
bool isFemale = inc.ReadBoolean();
|
bool isFemale = inc.ReadBoolean();
|
||||||
int headSpriteID = inc.ReadByte();
|
int headSpriteID = inc.ReadByte();
|
||||||
string jobName = inc.ReadString();
|
string jobName = inc.ReadString();
|
||||||
|
|
||||||
|
JobPrefab jobPrefab = null;
|
||||||
|
List<int> skillLevels = new List<int>();
|
||||||
|
if (!string.IsNullOrEmpty(jobName))
|
||||||
|
{
|
||||||
|
jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
|
||||||
|
int skillCount = inc.ReadByte();
|
||||||
|
for (int i = 0; i < skillCount; i++)
|
||||||
|
{
|
||||||
|
skillLevels.Add(inc.ReadRangedInteger(0, 100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!spawn) return null;
|
if (!spawn) return null;
|
||||||
|
|
||||||
JobPrefab jobPrefab = JobPrefab.List.Find(jp => jp.Name == jobName);
|
|
||||||
|
|
||||||
CharacterInfo ch = new CharacterInfo(configPath, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
|
CharacterInfo ch = new CharacterInfo(configPath, newName, isFemale ? Gender.Female : Gender.Male, jobPrefab);
|
||||||
ch.HeadSpriteId = headSpriteID;
|
ch.HeadSpriteId = headSpriteID;
|
||||||
|
|
||||||
character = Character.Create(configPath, position, ch, GameMain.Client.ID != ownerId, hasAi);
|
System.Diagnostics.Debug.Assert(skillLevels.Count == ch.Job.Skills.Count);
|
||||||
|
if (ch.Job != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < skillLevels.Count && i < ch.Job.Skills.Count; i++)
|
||||||
|
{
|
||||||
|
ch.Job.Skills[i].Level = skillLevels[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
character = Create(configPath, position, ch, GameMain.Client.ID != ownerId, hasAi);
|
||||||
character.ID = id;
|
character.ID = id;
|
||||||
character.TeamID = teamID;
|
character.TeamID = teamID;
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ namespace Barotrauma
|
|||||||
public int Level
|
public int Level
|
||||||
{
|
{
|
||||||
get { return level; }
|
get { return level; }
|
||||||
|
set { level = MathHelper.Clamp(value, 0, 100); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Skill(SkillPrefab prefab)
|
public Skill(SkillPrefab prefab)
|
||||||
|
|||||||
Reference in New Issue
Block a user