public virtual void AddPuppet(Civilization civ, IPuppetLevel puppetLevel) { civ.Master?._puppets.Remove(civ); civ.Master = this; civ._puppetLevel = puppetLevel.Clone(); _puppets.Add(civ); }
protected PuppetLevel(IPuppetLevel parent) { if (parent is PuppetLevel level) { Init(level.Data.Head); } else { var data = (PuppetLevelData)parent; Init(data.Head ?? (IPuppetLevel)data); } }
public T GetSpecialised <T>(bool create) where T : PuppetLevel, new() { if (this is T thisT) { return(thisT); } IPuppetLevel tmp = Data.Head; while (tmp is PuppetLevel) { if (tmp is T result) { return(result); } tmp = ((PuppetLevel)tmp).Parent; } return(create ? (T) new T().Init(Data.Head) : null); }
protected PuppetLevel Init(IPuppetLevel parent) { if (Parent != null) { throw new InvalidOperationException("Cannot be initialized twice"); } var tmp = parent; while (tmp is PuppetLevel casted) { if (tmp.GetType().IsAssignableFrom(GetType())) { throw new ArgumentException("All parents must be of different type"); } tmp = casted.Parent; } Parent = parent; Data = (PuppetLevelData)tmp; Data.Head = this; return(this); }
public virtual void MakeIndependent() { Master?._puppets.Remove(this); _puppetLevel = null; Master = null; }
public PuppetLevelAddition2(IPuppetLevel parent, bool addition2 = false) : base(parent) { Addition2 = addition2; }
public PuppetLevelAddition1(IPuppetLevel parent, bool addition1 = false) : base(parent) { Addition1 = addition1; }
public PuppetLevelAddition3(IPuppetLevel parent, bool addition3 = false) : base(parent) { Addition3 = addition3; }