private void OnUserVariableHandler(NEvent evt) { User user = evt.BaseEvt.Params["user"] as User; try { if (!user.IsItMe && user.Name == this.name) { ///同步位移 if (user.ContainsVariable("position")) { SFSObject so = (SFSObject)user.GetVariable("position").Value; this.transform.position = Vector3.Lerp(this.transform.position, new Vector3((float)so.GetDouble("x"), (float)so.GetDouble("y"), (float)so.GetDouble("z")), Time.deltaTime * 10); } ///同步旋转 if (user.ContainsVariable("rotation")) { SFSObject so = (SFSObject)user.GetVariable("rotation").Value; this.transform.eulerAngles = new Vector3(0, (float)so.GetDouble("y"), 0); } } } catch (Exception e) { print("出错" + e.Message); } }
public override void UpdateData(User user, SFSObject data) { int go_id = (data.ContainsKey(Consts.GO_ID)) ? (int)data.GetDouble(Consts.GO_ID) : -1; if (!(data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y))) { return; } if (go_id != -1) { if (_bullets.ContainsKey(go_id)) { _bullets[go_id].SetPosition(new Vector2((float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y))); } } base.UpdateData(user, data); }
public override void UpdateData(User user, SFSObject data) { User me = _network.GetInstance().MySelf; if (user != me && user != null) { if (_tanks.ContainsKey(user.Id)) { if (data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y) && data.ContainsKey(Consts.ROTATION)) { _tanks[user.Id].SetVariable((float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y), (int)data.GetDouble(Consts.ROTATION)); } } } base.UpdateData(user, data); }
public override void Add(Sfs2X.Entities.User user, SFSObject data) { if (_bullets != null) { if (data.ContainsKey(Consts.X) && (data.ContainsKey(Consts.Y) && data.ContainsKey(Consts.GO_ID))) { int objectId = (int)data.GetDouble(Consts.GO_ID); if (!_bullets.ContainsKey(objectId)) { _bullets.Add((int)data.GetDouble(Consts.GO_ID), new Bullet((float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y), (ulong)objectId)); _bullets[objectId].LoadContents(_contents); _s_fire.Play(); } } } base.Add(user, data); }
public override void Remove(User user, SFSObject data) { if (data.ContainsKey(Consts.GO_ID)) { int id = (int)data.GetDouble(Consts.GO_ID); if (_items.ContainsKey(id)) { _items.Remove(id); } } }
public override void UpdateData(User user, SFSObject data) { if (data.ContainsKey(Consts.BHVR) && data.ContainsKey(Consts.GO_ID)) { int id = (int)data.GetDouble(Consts.GO_ID); string behavior = (string)data.GetUtfString(Consts.BHVR); if (_items != null && _items.ContainsKey(id)) { _items[id].Behavior(behavior); } } }
private void OnExtensionResponse(BaseEvent e) { SFSObject receive = (SFSObject)e.Params["params"]; string cmd = (string)e.Params["cmd"]; Room room = (Room)e.Params["room"]; User sender = room.GetUserById((int)(receive.GetDouble("ID"))); List <User> list = room.UserList; // test // update data if (cmd == Consts.CMD_UPDATE_DATA) { if (sender == null) { Debug.WriteLine("Sender = null"); return; } string type = receive.GetUtfString(Consts.TYPE); if (type == Consts.TYPE_TANK) { _controllers[Consts.CTRL_TANK].UpdateData(sender, receive); } if (type == Consts.TYPE_BULLET) { _controllers[Consts.CTRL_BULLET].UpdateData(sender, receive); } } // add new object if (cmd == Consts.CMD_ADD) { string type = receive.GetUtfString(Consts.TYPE); if (type == Consts.TYPE_TANK) { _controllers[Consts.CTRL_TANK].Add(sender, receive); } if (type == Consts.TYPE_BULLET) { _controllers[Consts.CTRL_BULLET].Add(sender, receive); } } // remove object if (cmd == Consts.CMD_REMOVE) { string type = receive.GetUtfString(Consts.TYPE); if (type == Consts.TYPE_TANK) { _controllers[Consts.CTRL_TANK].Remove(sender, receive); } if (type == Consts.TYPE_BULLET) { _controllers[Consts.CTRL_BULLET].Remove(sender, receive); } } }
public override void Add(User user, SFSObject data) { if (_items != null) { if (!(data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y) && data.ContainsKey(Consts.GO_ID) && data.ContainsKey(Consts.TYPE_KIND_OF_ITEM))) { return; } float x = (float)data.GetDouble(Consts.X); float y = (float)data.GetDouble(Consts.Y); int id = (int)data.GetDouble(Consts.GO_ID); int itemKind = (int)data.GetDouble(Consts.TYPE_KIND_OF_ITEM); if (_items.ContainsKey(id)) { return; } #region add item switch (itemKind) { case 0: { _items.Add(id, new Item(x, y, Consts.ES_ITEM_HP)); break; } case 1: { _items.Add(id, new Item(x, y, Consts.ES_ITEM_POWER_UP)); break; } } #endregion _items[id].LoadContents(_contents); } }
public Brand(SFSObject aObject) { id = aObject.GetInt("ID"); owner = aObject.GetInt("Ow"); Debug.Log (aObject.ToJson()); try { fb = (long) Convert.ToInt64(aObject.GetFloat("FB")); } catch(Exception e) { try { fb = aObject.GetLong("FB"); } catch(Exception e2) { fb = (long) aObject.GetDouble("FB"); } } brand = aObject.GetUtfString("B"); }
public override void Add(User user, SFSObject data) { if (user != null) { if (data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y)) { if (!_tanks.ContainsKey(user.Id)) { _tanks.Add(user.Id, new Tank(user.Id, (float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y))); _tanks[user.Id].LoadContents(_contents); // AddOtherPlayer(data); } } } base.Add(user, data); }
public override void Remove(User user, SFSObject data) { if (!data.ContainsKey(Consts.GO_ID)) { return; } else { int objectId = (int)data.GetDouble(Consts.GO_ID); if (_bullets.ContainsKey(objectId)) { _bullets.Remove(objectId); } } base.Remove(user, data); }
public void loadFromSFSObject(SFSObject aSFSObject) { if(aSFSObject.GetSFSObject("horses")!=null) { aSFSObject = aSFSObject.GetSFSObject("horses") as SFSObject; } this.accelerationBase = aSFSObject.GetLong("Acceleration"); this.baseLayer = aSFSObject.GetInt("BaseLayer"); this.blanket = aSFSObject.GetInt("Blanket"); this.cadence = aSFSObject.GetLong("Cadence"); this.determination = aSFSObject.GetLong("Determination"); this.fatigue = aSFSObject.GetInt("Fatigue"); this.salePrice = aSFSObject.GetInt("ForSale"); this.happiness = aSFSObject.GetInt("Happiness"); this.headwear = aSFSObject.GetInt("Headwear"); Debug.LogError("TODO: Make this load health data"); // this.HealthDataFromString(aSFSObject.GetUtfString("HealthData")); this.height = aSFSObject.GetInt("Height"); Debug.LogError("TODO: Make this load horse record data"); //this.horseRecordFromString(aSFSObject.GetUtfString("HorseRecord")); this.horseScore = aSFSObject.GetInt("HorseScore"); this.hunger = aSFSObject.GetInt("Hunger"); this.horseID = aSFSObject.GetInt("ID"); this.jumping = aSFSObject.GetLong("Jumping"); this.lastUpdated = aSFSObject.GetInt("LastUpdate"); this.legWear = aSFSObject.GetInt("LegWear1"); this.legWear2 = aSFSObject.GetInt("LegWear2"); this.level = aSFSObject.GetInt("Level"); this.mane = aSFSObject.GetInt("Mane"); try { this.maxMPH = (float) aSFSObject.GetDouble("MaxSpeed"); } catch(Exception e) { try { this.maxMPH = aSFSObject.GetFloat("MaxSpeed"); } catch(Exception e2) { this.maxMPH = 0.0f; } } string nameStr = aSFSObject.GetUtfString("Name"); this._baseName = nameStr; try { if(aSFSObject.GetDouble("OriginalOwner")>0) this.originalOwnerID = (long) aSFSObject.GetDouble("OriginalOwner"); } catch(Exception e) { if(aSFSObject.GetLong("OriginalOwner")>0) this.originalOwnerID = aSFSObject.GetLong("OriginalOwner"); } if(aSFSObject.GetInt("OwnerID")>0) this.ownerID = (long) aSFSObject.GetInt("OwnerID"); //this.setPassportFromString(aSFSObject.GetUtfString("PassportString")); this.overlay = aSFSObject.GetInt("PatternLayer1"); this.potential = aSFSObject.GetInt("Potential"); this.birthTime = aSFSObject.GetInt("PregnantReturnTime"); this.recovery = aSFSObject.GetLong("Recovery"); this.reintype = aSFSObject.GetInt("ReinType"); this.trainingReturnTime = aSFSObject.GetInt("ReturnFromTrainingTime"); this.saddle = aSFSObject.GetInt("SaddleType"); this.gender= (EGender) aSFSObject.GetInt("Sex"); this.speed = aSFSObject.GetLong("Speed"); this._stamina = aSFSObject.GetLong("Stamina"); this.stridelength = aSFSObject.GetLong("StrideLength"); this.surfacePreference = (ESurfaceType) aSFSObject.GetInt("SurfacePreference"); this.tail = aSFSObject.GetInt("Tail"); if(tail>0&&tail<12300) { tail = 12300; } if(mane>0&&mane<12200) { mane = 12200; } this.horseTalents.talents = (aSFSObject.GetUtfString("Talents")); this.dateborn = aSFSObject.GetInt("TimeCreated"); Debug.LogError("TODO: Make this load trophies owned"); //this.trophiesOwned(aSFSObject.GetUtfString("Trophies")); this.xp = aSFSObject.GetLong("XP"); this.studFee = (long) aSFSObject.GetInt("StudFee"); this.personalityBigRacer = aSFSObject.GetInt("PersonalityBigRacer"); this.personalityProfessional = aSFSObject.GetInt("PersonalityProfessional"); this.personalityAdaptable = aSFSObject.GetInt("PersonalityAdaptable"); this.personalityJumper = aSFSObject.GetInt("PersonalityA"); this.personalityChaser = aSFSObject.GetInt("PersonalityB"); this.motherID = aSFSObject.GetInt("Mother"); this.fatherID = aSFSObject.GetInt("Father"); }