public WorldStateCollection(IWorldSpace area, WorldState[] states) { Area = area; States = states; CompiledState = new byte[8 * States.Length]; // init default states for (var i = 0; i < States.Length; i++) { var state = States[i]; Array.Copy(BitConverter.GetBytes((uint)state.Key), 0, CompiledState, i * 8, 4); Array.Copy(BitConverter.GetBytes(state.DefaultValue), 0, CompiledState, 4 + i * 8, 4); } }
static WorldStates() { CreateStates(); foreach (var state in AllStates) { if (state != null) { WorldState[] arr; if (state.ZoneId != ZoneId.None) { arr = GetStates(state.ZoneId); if (arr == null) { arr = new WorldState[1]; } ArrayUtil.AddOnlyOne(ref arr, state); ZoneStates[(int)state.MapId] = arr; } else if (state.MapId != MapId.End) { arr = GetStates(state.MapId); if (arr == null) { arr = new WorldState[1]; } ArrayUtil.AddOnlyOne(ref arr, state); MapStates[(int)state.MapId] = arr; } else { ArrayUtil.AddOnlyOne(ref GlobalStates, state); arr = GlobalStates; } state.Index = (uint)arr.Length - 1; } } }
private static void AddState(WorldState state) { AllStates[(int)state.Key] = state; }
public static void SendUpdateWorldState(IPacketReceiver rcv, WorldState state) { SendUpdateWorldState(rcv, state.Key, state.DefaultValue); }
private void OnStateChanged(WorldState state, int value) { Area.CallOnAllCharacters(chr => WorldStateHandler.SendUpdateWorldState(chr, state.Key, value)); }
public void SetUInt32(WorldState state, uint value) { Array.Copy(BitConverter.GetBytes(value), 0, CompiledState, 4 + state.Index * 8, 4); OnStateChanged(state, (int)value); }