/// <inheritdoc /> public void AppendSetData(IPersistedData data, long txtime, byte[] prevData, IMutableStat prevStat) { if (data == null) { throw new ArgumentNullException("data"); } if (prevStat == null) { throw new ArgumentNullException("prevStat"); } if (this.changelist == null) { this.changelist = this.createChangeList(); } data.AppendSetData(this.changelist); if (this.changelist != null) { this.changelist.SetTime(txtime); } if (this.isLockDown) { return; } this.RunOnAbort(() => { data.Data = prevData; data.Stat = prevStat; }); }
public void Awake() { MaxHealthStat = new PlayerStat(3); DamageStat = new PlayerStat(10); DefenseStat = new PlayerStat(0); Health = MaxHealthStat.Value; }
public void ExecuteEffect(IMutableStat stat) { var modifier = new StatModifier(defenseBuff, this); if (!stat.IsModified) { stat.AddModifier(modifier); } else { stat.RemoveAllModifierFromSource(this); stat.AddModifier(modifier); } }
/// <summary> /// Turns the value into a first stat if it makes sense. /// </summary> /// <param name="value">The value.</param> /// <returns>the original value, or a firststat that is equivalent to it</returns> public static IMutableStat TurnIntoFirstStatIfNeeded(IMutableStat value) { if (value != null && value.Version == 1 && value.Aversion == 1 && value.Cversion == 1 && value.NumChildren == 0 && value.Ctime == value.Mtime && value.Czxid == value.Mzxid && value.Pzxid == value.Czxid) { return(new FirstStat(value)); } return(value); }
/// <summary> /// Determines whether the specified <see cref="object"/> is equal to this instance. /// </summary> /// <param name="obj">The object to compare with the current object.</param> /// <returns><c>true</c> if the specified <see cref="object"/> is equal to this instance; otherwise, <c>false</c>.</returns> public override bool Equals(object obj) { IMutableStat other = obj as IMutableStat; if (other == null) { return(false); } return(this.Czxid == other.Czxid && this.Mzxid == other.Mzxid && this.Ctime == other.Ctime && this.Mtime == other.Mtime && this.Version == other.Version && this.Cversion == other.Cversion && this.Aversion == other.Aversion && this.DataLength == other.DataLength && this.NumChildren == other.NumChildren && this.NumEphemeralChildren == other.NumEphemeralChildren && this.Pzxid == other.Pzxid); }
/// <summary> /// computes the unique incarnation id for an arbitrary IStat /// </summary> /// <param name="stat">the stat to evaluate</param> /// <param name="useExtended">if true, the returned guid is an extended incarnation id (including children version)</param> /// <returns>the unique incarnation id for the stat</returns> public static Guid GetUniqueIncarnationId(IMutableStat stat, bool useExtended) { if (stat == null) { return(Guid.Empty); } int a = stat.Version; short b = 0; short c = 0; byte[] bytes = BitConverter.GetBytes(stat.Ctime); if (useExtended) { b = (short)(((ushort)stat.Cversion) >> 2); c = (short)(stat.Cversion % 0xffff); } return(new Guid(a, b, c, bytes)); }
/// <summary> /// Initializes a new instance of the <see cref="PersistedData"/> class. /// </summary> /// <param name="id">Unique Id</param> /// <param name="unused">Unused factory object, for backward compatibility</param> public PersistedData(ulong id, AbstractPersistedDataFactory unused) { this.Id = id; this.stat = new MutableStat(); }
/// <summary> /// Appends a move operation. /// </summary> /// <param name="parentSrc">The parent node where the moved node lives.</param> /// <param name="parentDst">The parent node where the node will move into.</param> /// <param name="child">The child node moved.</param> /// <param name="txTime">The tx time.</param> /// <param name="prevChildStat">The previous child stat.</param> /// <param name="prevStatParentSrc">The previous stat parent source.</param> /// <param name="prevStatParentDst">The previous stat parent DST.</param> public void AppendMove(IPersistedData parentSrc, IPersistedData parentDst, IPersistedData child, long txTime, IMutableStat prevChildStat, IMutableStat prevStatParentSrc, IMutableStat prevStatParentDst) { if (child == null) { throw new ArgumentNullException("child"); } if (parentSrc == null) { throw new ArgumentNullException("parentSrc"); } if (parentDst == null) { throw new ArgumentNullException("parentDst"); } if (prevChildStat == null) { throw new ArgumentNullException("prevChildStat"); } if (prevChildStat == null) { throw new ArgumentNullException("prevChildStat"); } if (prevStatParentSrc == null) { throw new ArgumentNullException("prevStatParentSrc"); } if (prevChildStat == null) { throw new ArgumentNullException("prevChildStat"); } if (prevStatParentDst == null) { throw new ArgumentNullException("prevStatParentDst"); } if (this.changelist == null) { this.changelist = this.createChangeList(); } parentSrc.AppendRemoveChild(this.changelist, child); parentDst.AppendAddChild(this.changelist, child); if (this.changelist != null) { this.changelist.SetTime(txTime); } if (this.isLockDown) { return; } this.RunOnAbort(() => { this.ValidateLockList(parentDst, Perm.WRITE, null, Perm.NONE); this.ValidateLockList(parentSrc, Perm.WRITE, null, Perm.NONE); parentDst.Node.RemoveChild(child.Name); parentSrc.Node.AddChild(child.Node); child.Stat = prevChildStat; parentDst.Stat = prevStatParentDst; parentSrc.Stat = prevStatParentSrc; }); }
/// <inheritdoc /> public void AppendRemove(IPersistedData parent, IPersistedData child, long txtime, IMutableStat prevChildStat, IMutableStat prevParentStat, Action recordUndeleteAction) { if (child == null) { throw new ArgumentNullException("child"); } if (parent == null) { throw new ArgumentNullException("parent"); } if (prevChildStat == null) { throw new ArgumentNullException("prevChildStat"); } if (prevParentStat == null) { throw new ArgumentNullException("prevParentStat"); } if (recordUndeleteAction == null) { throw new ArgumentNullException("recordUndeleteAction"); } if (this.changelist == null) { this.changelist = this.createChangeList(); } child.AppendRemove(this.changelist, parent); if (this.changelist != null) { this.changelist.SetTime(txtime); } if (this.isLockDown) { return; } this.RunOnAbort(() => { this.ValidateLockList(parent, Perm.WRITE, null, Perm.NONE); recordUndeleteAction(); parent.Node.AddChild(child.Node); child.Stat = prevChildStat; parent.Stat = prevParentStat; }); }
/// <summary> /// Initializes a new instance of the <see cref="MutableStat"/> class. /// </summary> /// <param name="other">The other.</param> public MutableStat(IMutableStat other) : this((IStat)other) { this.NumEphemeralChildren = other.NumEphemeralChildren; }
/// <inheritdoc /> public void AppendSetData(IPersistedData persisted, long txTime, byte[] prevData, IMutableStat prevStat) { throw new NotSupportedException(); }
/// <inheritdoc /> public void AppendSetAcl(IPersistedData persisted, long txTime, IReadOnlyList <Acl> prevAcl, IMutableStat prevStat) { throw new NotSupportedException(); }
/// <inheritdoc /> public void AppendMove(IPersistedData parentSrc, IPersistedData parentDst, IPersistedData child, long txTime, IMutableStat prevChildStat, IMutableStat prevStatParentSrc, IMutableStat prevStatParentDst) { throw new NotSupportedException(); }
/// <inheritdoc /> public void AppendRemove(IPersistedData parent, IPersistedData child, long txTime, IMutableStat prevChildStat, IMutableStat prevParentStat, Action recordUndeleteAction) { throw new NotSupportedException(); }
/// <inheritdoc /> public void AppendAddChild(IPersistedData persisted, IPersistedData childData, long txTime, IMutableStat prevStat) { throw new NotSupportedException(); }