public void ReadExternal(IDataInput input) { string json = input.ReadUTF(); //DataContractJsonSerializer serialiser = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(BroadcastNotification)); //Stream stream = new MemoryStream(ASCIIEncoding.Default.GetBytes(json)); //BroadcastNotification notification = (BroadcastNotification)serialiser.ReadObject(stream); broadcastMessages = new ArrayCollection() ; }
public void WriteData(AMFWriter writer, object data) { if (data is ArrayCollection) { writer.WriteByte(AMF3TypeCode.Object); writer.WriteAMF3Object(data); return; } //TODO: configure somehow Vector support /* if (CollectionUtils.IsGenericListType(data.GetType())) { Type itemType = ReflectionUtils.GetListItemType(data.GetType()); switch (Type.GetTypeCode(itemType)) { case TypeCode.Int32: writer.WriteByte(AMF3TypeCode.IntVector); writer.WriteAMF3IntVector(data as IList<int>); return; case TypeCode.UInt32: writer.WriteByte(AMF3TypeCode.UIntVector); writer.WriteAMF3UIntVector(data as IList<uint>); return; case TypeCode.Double: writer.WriteByte(AMF3TypeCode.NumberVector); writer.WriteAMF3DoubleVector(data as IList<double>); return; case TypeCode.String: writer.WriteByte(AMF3TypeCode.ObjectVector); writer.WriteAMF3ObjectVector(data as IList<string>); return; case TypeCode.Boolean: writer.WriteByte(AMF3TypeCode.ObjectVector); writer.WriteAMF3ObjectVector(data as IList<bool>); return; default: writer.WriteByte(AMF3TypeCode.ObjectVector); writer.WriteAMF3ObjectVector(data as IList); return; } } */ var list = data as IList; if (list != null ) { //http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001104.html#270405 //http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001105.html#268711 if( writer.UseLegacyCollection ) { writer.WriteByte(AMF3TypeCode.Array); writer.WriteAMF3Array(list); } else { writer.WriteByte(AMF3TypeCode.Object); object value = new ArrayCollection(list); writer.WriteAMF3Object(value); } return; } #if !(SILVERLIGHT) var listSource = data as IListSource; if (listSource != null) { if (writer.UseLegacyCollection) { writer.WriteByte(AMF3TypeCode.Array); writer.WriteAMF3Array(listSource.GetList()); } else { writer.WriteByte(AMF3TypeCode.Object); object value = new ArrayCollection(listSource.GetList()); writer.WriteAMF3Object(value); } return; } #endif var dictionary = data as IDictionary; if (dictionary != null) { //writer.WriteByte(AMF3TypeCode.Object); //writer.WriteAMF3Object(data); writer.WriteByte(AMF3TypeCode.Array); writer.WriteAMF3AssociativeArray(dictionary); return; } if(data is Exception) { writer.WriteByte(AMF3TypeCode.Object); if (writer.UseLegacyThrowable) writer.WriteAMF3Object(new ASExceptionObject(data as Exception) ); else writer.WriteAMF3Object(data); return; } if( data is IExternalizable ) { writer.WriteByte(AMF3TypeCode.Object); writer.WriteAMF3Object(data); return; } if (data is IEnumerable) { var enumerator = (data as IEnumerable).GetEnumerator(); #if !(NET_1_1) var tmp = new List<object>(); #else ArrayList tmp = new ArrayList(); #endif foreach (var element in (data as IEnumerable)) { tmp.Add(element); } if (writer.UseLegacyCollection) { writer.WriteByte(AMF3TypeCode.Array); writer.WriteAMF3Array(tmp); } else { writer.WriteByte(AMF3TypeCode.Object); object value = new ArrayCollection(tmp); writer.WriteAMF3Object(value); } return; } writer.WriteByte(AMF3TypeCode.Object); writer.WriteAMF3Object(data); }
/// <summary> /// This type supports the Fluorine infrastructure and is not intended to be used directly from your code. /// </summary> /// <param name="context">An ITypeDescriptorContext that provides a format context.</param> /// <param name="culture">A CultureInfo object. If a null reference (Nothing in Visual Basic) is passed, the current culture is assumed.</param> /// <param name="value">The Object to convert.</param> /// <param name="destinationType">The Type to convert the value parameter to.</param> /// <returns>An Object that represents the converted value.</returns> public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { ArrayCollection ac = value as ArrayCollection; ValidationUtils.ArgumentNotNull(ac, "value"); if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(ArrayCollection)) { return(value); } if (destinationType.IsArray) { return(ac.ToArray()); } #if !SILVERLIGHT if (destinationType == typeof(ArrayList)) { if (ac.List is ArrayList) { return(ac.List); } return(ArrayList.Adapter(ac.List)); } #endif if (destinationType == typeof(IList)) { return(ac.List); } //generic interface Type typeGenericICollection = destinationType.GetInterface("System.Collections.Generic.ICollection`1", false); if (typeGenericICollection != null) { object obj = TypeHelper.CreateInstance(destinationType); MethodInfo miAddCollection = typeGenericICollection.GetMethod("Add"); if (miAddCollection != null) { ParameterInfo[] parameters = miAddCollection.GetParameters(); if (parameters != null && parameters.Length == 1) { Type parameterType = parameters[0].ParameterType; IList list = (IList)value; for (int i = 0; i < list.Count; i++) { miAddCollection.Invoke(obj, new object[] { TypeHelper.ChangeType(list[i], parameterType) }); } return(obj); } } } Type typeIList = destinationType.GetInterface("System.Collections.IList", false); if (typeIList != null) { object obj = TypeHelper.CreateInstance(destinationType); IList list = obj as IList; for (int i = 0; i < ac.List.Count; i++) { list.Add(ac.List[i]); } return(obj); } #if !SILVERLIGHT return(base.ConvertTo(context, culture, value, destinationType)); #else return(base.ConvertTo(value, destinationType)); #endif }
void InitEnv() { CallBackEvents.Add(Conf.USER_FACADE + "#" + Conf.LOGIN_ACCOUNT, data => { var vo = data as SysUserVO; //var vo = JObject.FromObject(data).ToObject<SysUserVO>(); if (vo != null) { Debug.Log("login success"); SessionInfo._currentSysUserVO = vo; } else { Debug.Log("login failed"); } }); //CallBackEvents.Add(Conf.PK_MATCH_FACADE + "#" + Conf.AUTO_MATCH, // data => // { // }); NotifyEvents.Add(Conf.BATTLE_MATCH_SUCCESS, data => { Debug.Log("Match success"); //切换到战斗界面 //然后发送UIReady NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.UI_READY, null); }); NotifyEvents.Add(Conf.BATTLE_INIT_DONE, data => { var bro = data as BattleResultBo; if (bro != null) { Debug.Log("BattleInitDone..."); _currentBRB = bro; _todoQue.Enqueue(Conf.BATTLE_INIT_DONE); } }); NotifyEvents.Add(Conf.BATTLE_TIME_IN, data => { _todoQue.Enqueue(Conf.BATTLE_TIME_IN); }); NotifyEvents.Add(Conf.BATTLE_OPT_DONE, data => { var bro = data as BattleResultBo; if (bro != null) { _currentBRB = bro; //播放操作... _todoQue.Enqueue(Conf.BATTLE_OPT_DONE); } }); NotifyEvents.Add(Conf.BATTLE_OVER_TIME, data => { _todoQue.Enqueue(Conf.BATTLE_OVER_TIME); }); _todoQue = new Queue<string>(); _todoDic = new Dictionary<string, Action>(); //战斗初始化 _todoDic.Add(Conf.BATTLE_INIT_DONE, () => { for (int i = 0; i < _currentBRB.halfRound.boardPokers.Count; i++) { //_boardPokers[i].Poker = _currentBRB.halfRound.boardPokers[i]; _boardPokers[_currentBRB.halfRound.boardPokers[i].pos - 1].Poker = _currentBRB.halfRound.boardPokers[i]; } if (IsMe()) { _self.Player = _currentBRB.halfRound.atk; _opponent.Player = _currentBRB.halfRound.def; } else { _self.Player = _currentBRB.halfRound.def; _opponent.Player = _currentBRB.halfRound.atk; } _self.NameLabel.text = _self.Player.pName; _opponent.NameLabel.text = _opponent.Player.pName; _self.HPLable.text = _self.Player.pHp + "/" + _self.Player.pHpMax; _opponent.HPLable.text = _opponent.Player.pHp + "/" + _opponent.Player.pHpMax; //完成后发送AnimReady NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.ANIM_READY, null); }); //战斗主消息 _todoDic.Add(Conf.BATTLE_OPT_DONE, () => { //_currentBRB.halfRound.detailMfs[0].opt for (int i = 0; i < _currentBRB.halfRound.detailMfs.Count; i++) { var op = _currentBRB.halfRound.detailMfs[i].opt; //Debug.Log(1); var itsyou = op.optOr.pType == 0 && op.optOr.pId == SessionInfo._currentSysUserVO.suId; Debug.Log("odMfs Count" + _currentBRB.halfRound.detailMfs[i].odMfs.Count); for (int j = 0; j < _currentBRB.halfRound.detailMfs[i].odMfs.Count; j++) { var odmf = _currentBRB.halfRound.detailMfs[i].odMfs[j]; if (itsyou) { _self.Player.pHp += odmf.hpMf; _self.HPLable.text = _self.Player.pHp + "/" + _self.Player.pHpMax; } else { _opponent.Player.pHp += odmf.hpMf; _opponent.HPLable.text = _opponent.Player.pHp + "/" + _opponent.Player.pHpMax; } } switch (op.optType) { case OptType.NONE: Debug.Log("飘窗"); if (_currentBRB.halfRound.round == 1) { //第一回合重置棋盘 _boardPokers[_currentBRB.halfRound.boardPokers[i].pos - 1].Poker = _currentBRB.halfRound.boardPokers[i]; } break; case OptType.SKIP: Debug.Log("跳过"); break; case OptType.MAJORSKILL: Debug.Log("武将技"); break; case OptType.PLAYAHAND: if (itsyou) { } else { Debug.Log("敌方出牌"); for (int j = 0; j < op.lineOpt.pokerLines.Count; j++) { //Debug.Log("from: " + op.lineOpt.pokerLines[j].from + " to: " + op.lineOpt.pokerLines[j].to); } for (int j = 0; j < op.lineOpt.pokerMfs.Count; j++) { //Debug.Log("handpos: " + op.lineOpt.pokerMfs[j].handPoker.pos + " etype: " + op.lineOpt.pokerMfs[j].handPoker.elementType); var ophp = _opponent.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1]; var bdp = _boardPokers[op.lineOpt.pokerMfs[j].boardPos - 1]; //bdp.gameObject.SetActive(false); //ophp.transform.parent = _board.transform; //ophp.transform.localPosition = bdp.transform.localPosition; bdp.Poker = ophp.Poker; ophp.Poker = null; } } break; case OptType.FILLHAND: if (itsyou) { Debug.Log("玩家补牌"); for (int j = 0; j < op.lineOpt.pokerMfs.Count; j++) { //Debug.Log( op.lineOpt.pokerMfs[j].handPoker.pos); //Debug.Log(_self.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1].transform.parent.name); var shp = _self.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1]; shp.Reset(); shp.Poker = op.lineOpt.pokerMfs[j].handPoker; shp.gameObject.SetActive(true); } } else { Debug.Log("敌方补牌"); for (int j = 0; j < op.lineOpt.pokerMfs.Count; j++) { //Debug.Log(op.lineOpt.pokerMfs[j].handPoker.pos); var shp = _opponent.HandPokers[op.lineOpt.pokerMfs[j].handPoker.pos - 1]; shp.Reset(); shp.Poker = op.lineOpt.pokerMfs[j].handPoker; shp.gameObject.SetActive(true); } } break; default: break; } } if (_currentBRB.halfRound.gameOver) { Debug.Log("Game Over"); } else { //完成后发送AnimReady NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.ANIM_READY, null); } }); //战斗计时开始 _todoDic.Add(Conf.BATTLE_TIME_IN, () => { if (IsMe()) { Debug.Log("玩家回合开始"); _self.HandPokers.ForEach(d => { if (d.Poker != null) { d.collider2D.enabled = true; } //d.GetComponent<DragItem>().Reset(); }); } else { Debug.Log("敌方回合开始"); } }); //战斗超时 _todoDic.Add(Conf.BATTLE_OVER_TIME, () => { _canOpt = false; _self.HandPokers.ForEach(d => d.collider2D.enabled = false); }); _board = NGUITools.AddChild(gameObject); _board.name = "board"; //初始化棋盘 _boardPokers = new List<PokerMono>(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { var go = CreateTestCommponent(_board, "空", new Vector3(Screen.width * -0.2f + Screen.width * j * 0.1f, Screen.height * 0.24f - Screen.height * i * 0.12f), true); var pm = go.AddComponent<PokerMono>(); pm.Label = go.GetComponent<UILabel>(); _boardPokers.Add(pm); } } //初始化玩家 var p = NGUITools.AddChild(gameObject); p.name = "player"; _self = p.AddComponent<PlayerMono>(); var name = CreateTestCommponent(p, "P1", Vector3.zero, false); var hp = CreateTestCommponent(p, "100", new Vector3(0, -Screen.height * 0.12f), false); _self.NameLabel = name.GetComponent<UILabel>(); _self.HPLable = hp.GetComponent<UILabel>(); _self.HandPokers = new List<PokerMono>(); for (int i = 0; i < 5; i++) { var oriPos = new Vector3(-Screen.width * 0.1f + Screen.width * i * 0.05f, -Screen.height * 0.24f); var handp = CreateTestCommponent(p, "空", oriPos, true); var pkm = handp.AddComponent<PokerMono>(); pkm.Label = handp.GetComponent<UILabel>(); pkm.OriPos = oriPos; pkm.OriParent = p.transform; var ut = GetComponent<UIRoot>(); var di = handp.AddComponent<DragItem>(); di.UT = ut; di.PM = pkm; di.OnDragStart = () => { //Debug.Log("drag start"); //取出第一张 if (_self.FirstP != null) { //确定是否在牌桌上 if (di.transform.parent != pkm.OriParent) { //_self.FirstP.gameObject.SetActive(true); _boardPokers[_self.FirstP.InTablePos - 1].gameObject.SetActive(true); _self.FirstP = null; } } }; //var posT1 = new int[] { 1, 5, 21, 25 }; var posT2 = new int[] { 2, 3, 4, 22, 23, 24 }; var posT3 = new int[] { 6, 10, 11, 15, 16, 20, }; di.OnDropOnTable = go => { //牌桌上的牌 var pt = go.GetComponent<PokerMono>(); //手牌 var ph = di.GetComponent<PokerMono>(); if (pt.Poker.valid) { pkm.Reset(); } else { //放第一张 if (_self.FirstP == null) { _self.FirstP = ph; _self.FirstP.InTablePos = pt.Poker.pos; Debug.Log("FirstP in Table:" + _self.FirstP.InTablePos); go.SetActive(false); di.transform.parent = go.transform.parent; di.transform.localPosition = go.transform.localPosition; di.collider2D.enabled = true; } //放第二张 else { //Debug.Log("lololo"); //Debug.Log(_self.FirstP.Poker.pos); var p1 = _self.FirstP.InTablePos; var p2 = pt.Poker.pos; var ok = false; if ((p1 == 1 && p2 == 25) || (p1 == 25 && p2 == 1) || (p1 == 5 && p2 == 21) || (p1 == 21 && p2 == 5)) { //Debug.Log("T1 OK"); ok = true; } else if (posT2.Contains(p1) && (p2 == p1 + 20 || p2 == p1 - 20)) { //Debug.Log("T2 OK"); ok = true; } else if (posT3.Contains(p1) && ((p2 < p1 && p2 == p1 - 4) || (p2 > p1 && p2 == p1 + 4))) { ok = true; if (p1 == 6 && p2 == 2) { ok = false; } //if (ok) Debug.Log("T3 OK"); } if (ok) { _self.SecondP = ph; _self.SecondP.InTablePos = pt.Poker.pos; var bp1 = _boardPokers[_self.FirstP.InTablePos - 1]; bp1.Poker = _self.FirstP.Poker; bp1.gameObject.SetActive(true); var bp2 = _boardPokers[_self.SecondP.InTablePos - 1]; bp2.Poker = _self.SecondP.Poker; //Debug.Log("lasdoasd: " + _self.HandPokers.Any(g => !g.gameObject.activeSelf)); ArrayCollection pokers = new ArrayCollection(); pokers.Add(new PokerMf() { boardPos = p1, handPoker = _self.FirstP.Poker }); pokers.Add(new PokerMf() { boardPos = p2, handPoker = ph.Poker }); Hashtable ht = new Hashtable() { {Conf.OPT_TOKEN, _currentBRB.halfRound.lastOpt.optToken}, {Conf.OPT_TYPE,(int)OptType.PLAYAHAND}, {Conf.HAND_POKERS,pokers} }; NetCtrl.SocketClient.Send(Conf.PK_MATCH_FACADE, Conf.DO_OPT, ht); //重置 _self.FirstP.Reset(); _self.SecondP.Reset(); _self.FirstP.Poker = _self.SecondP.Poker = null; _self.FirstP = _self.SecondP = null; _canOpt = false; _self.HandPokers.ForEach(d => d.collider2D.enabled = false); } else { Debug.Log("wrong put"); pkm.Reset(); } } } }; handp.collider2D.enabled = false; _self.HandPokers.Add(pkm); } p.transform.localPosition = new Vector3(-Screen.width * 0.38f, 0); //对手 p = NGUITools.AddChild(gameObject); p.name = "opponent"; _opponent = p.AddComponent<PlayerMono>(); name = CreateTestCommponent(p, "P2", Vector3.zero, false); hp = CreateTestCommponent(p, "100", new Vector3(0, -Screen.height * 0.12f), false); _opponent.NameLabel = name.GetComponent<UILabel>(); _opponent.HPLable = hp.GetComponent<UILabel>(); _opponent.HandPokers = new List<PokerMono>(); for (int i = 0; i < 5; i++) { var oriPos = new Vector3(-Screen.width * 0.1f + Screen.width * i * 0.05f, -Screen.height * 0.24f); var handp = CreateTestCommponent(p, "空", oriPos, true); var pkm = handp.AddComponent<PokerMono>(); pkm.Label = handp.GetComponent<UILabel>(); handp.collider2D.enabled = false; _opponent.HandPokers.Add(pkm); } p.transform.localPosition = new Vector3(Screen.width * 0.38f, 0); _canOpt = false; }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { object obj2; IList list; int num; ArrayCollection arrays = value as ArrayCollection; ValidationUtils.ArgumentNotNull(arrays, "value"); if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(ArrayCollection)) { return(value); } if (destinationType.IsArray) { return(arrays.ToArray()); } if (destinationType == typeof(ArrayList)) { if (arrays.List is ArrayList) { return(arrays.List); } return(ArrayList.Adapter(arrays.List)); } if (destinationType == typeof(IList)) { return(arrays.List); } if (destinationType.GetInterface("System.Collections.Generic.ICollection`1", false) != null) { obj2 = TypeHelper.CreateInstance(destinationType); MethodInfo method = destinationType.GetMethod("Add"); if (method != null) { ParameterInfo[] parameters = method.GetParameters(); if ((parameters != null) && (parameters.Length == 1)) { Type parameterType = parameters[0].ParameterType; list = (IList)value; for (num = 0; num < list.Count; num++) { method.Invoke(obj2, new object[] { TypeHelper.ChangeType(list[num], parameterType) }); } return(obj2); } } } if (destinationType.GetInterface("System.Collections.IList", false) != null) { obj2 = TypeHelper.CreateInstance(destinationType); list = obj2 as IList; for (num = 0; num < arrays.List.Count; num++) { list.Add(arrays.List[num]); } return(obj2); } return(base.ConvertTo(context, culture, value, destinationType)); }