/// <summary> /// Returns the Name of a Want (or null if none was found) /// </summary> /// <param name="wt">The Type of the Want</param> /// <param name="id">The id of the String</param> /// <returns>The Name or null</returns> public string FindName(WantType wt, uint id) { Hashtable ht = (Hashtable)Map[wt]; if (ht != null) { return((string)ht[id]); } return(null); }
/// <summary> /// Returns an ArrayLIst of Alias Object with all available Names for this Type /// </summary> /// <param name="wt">The Type of the Want</param> /// <returns>List of Alias Items</returns> public ArrayList GetNames(WantType wt) { ArrayList ret = new ArrayList(); Hashtable ht = (Hashtable)Map[wt]; if (ht != null) { foreach (uint t in ht.Keys) { Data.Alias a = new SimPe.Data.Alias(t, (string)ht[t], "{name}"); ret.Add(a); } } return(ret); }
/// <summary> /// Unserializes a BinaryStream into the Attributes of this Instance /// </summary> /// <param name="reader">The Stream that contains the FileData</param> public void Unserialize(System.IO.BinaryReader reader) { version = reader.ReadUInt32(); siminst = reader.ReadUInt16(); guid = reader.ReadUInt32(); type = (WantType)reader.ReadByte(); if (type == WantType.Skill) { data = reader.ReadUInt16(); } else if (type == WantType.Sim) { if (version >= 8) { data = reader.ReadUInt16(); } else { data = 0; } } else if ((byte)type > 1) { data = reader.ReadUInt32(); } else { data = 0; } property = reader.ReadUInt16(); counter = reader.ReadUInt32(); score = reader.ReadInt32(); if (version >= 9) { influence = reader.ReadInt32(); } flag = new WantFlags(reader.ReadByte()); }
void NextTask() { WantType highestWant = (WantType)0; for (int i = 1; i < (int)WantType.SIZE; i++) { if (wants[(WantType)i] > wants[highestWant]) { highestWant = (WantType)i; } } if (highestWant != currentTask) { currentTask = highestWant; switch (highestWant) { case WantType.Hunger: Scheduler.AddTask(FindFood, false); break; case WantType.Safety: Scheduler.AddTask(FindSafety, false); break; case WantType.Sleep: Scheduler.AddTask(FindRest, false); break; case WantType.Socialization: Scheduler.AddTask(FindSocialization, false); break; default: break; } } }
public static IList<SystemWants> GetSystemWants(WantType type, int count) { try { List<SystemWants> objs = new List<SystemWants>(); //随机取count个记录 double random = new Random(DateTime.Now.Second).NextDouble(); objs = getwants(type, count, random, Query.GTE("Random", random)); if (objs.Count < count) { objs = getwants(type, count, random, Query.LTE("Random", random)); } return objs; } catch (System.Exception err) { throw new CBB.ExceptionHelper.OperationException( CBB.ExceptionHelper.ErrType.SystemErr, CBB.ExceptionHelper.ErrNo.DBOperationError, err); } }
private static List<SystemWants> getwants(WantType type, int count, double random, QueryConditionList qc) { MongoCursor<SystemWants> mc = MongoDBHelper.GetCursor<SystemWants>( "SystemWants", Query.And(Query.EQ("type", type), qc), new SortByDocument("Random", 1), 1, count); List<SystemWants> objs = new List<SystemWants>(); objs.AddRange(mc); return objs; }