using System.Collections.Generic; using System.Security.AccessControl; using PSO2SERVER.Protocol.Packets; namespace PSO2SERVER.Models { public class Flags { public enum FlagType : uint { /// Flag is account related. Account, /// Flag is character related. Character, } private List flags = new List(); private List paramsList = new List(); public void Set(int id, byte val) { int index = id / 8; byte bitIndex = (byte)(id % 8); while (flags.Count <= index) flags.Add(0); flags[index] = SetBit(flags[index], bitIndex, val); } public byte Get(int id) { int index = id / 8; byte bitIndex = (byte)(id % 8); if (index >= flags.Count) return 0; return (byte)((flags[index] & (1 << bitIndex)) >> bitIndex); } public void SetParam(int id, uint val) { while (paramsList.Count <= id) paramsList.Add(0); paramsList[id] = val; } public uint GetParam(int id) { if (id >= paramsList.Count) return 0; return paramsList[id]; } public AccountFlagsPacket ToAccountFlags() { var aflags = new AccountFlagsPacket(); aflags.Flags.SetListItem(flags); aflags.Params.SetListItem(paramsList); return aflags; } public CharacterFlagsPacket ToCharFlags() { var cflags = new CharacterFlagsPacket(); cflags.Flags.SetListItem(flags); cflags.Params.SetListItem(paramsList); return cflags; } private static byte SetBit(byte byteValue, byte index, byte val) { byteValue &= (byte)~(1 << index); return (byte)(byteValue | ((val & 1) << index)); } } }