private bool parseCreatureSpeak(NetworkMessage incMsg, NetworkMessage outMsg) { uint unknown = incMsg.GetUInt32(); outMsg.AddUInt32(unknown); String senderName = incMsg.GetString(); outMsg.AddString(senderName); ushort senderLevel = incMsg.GetUInt16(); outMsg.AddUInt16(senderLevel); SpeechType type = (SpeechType)incMsg.GetByte(); outMsg.AddByte((byte)type); switch (type) { case SpeechType.Say: case SpeechType.Whisper: case SpeechType.Yell: case SpeechType.MonsterSay: case SpeechType.MonsterYell: case SpeechType.PrivateNPCToPlayer: Position position = incMsg.GetPosition(); outMsg.AddPosition(position); break; case SpeechType.ChannelRed: case SpeechType.ChannelRedAnonymous: case SpeechType.ChannelOrange: case SpeechType.ChannelYellow: case SpeechType.ChannelWhite: ChatChannel channelId = (ChatChannel)incMsg.GetUInt16(); outMsg.AddUInt16((ushort)channelId); break; case SpeechType.RuleViolationReport: uint time = incMsg.GetUInt32(); outMsg.AddUInt32(time); break; case SpeechType.Private: break; default: Logger.Log("Tipo de mensagem desconhecido.", LogType.ERROR); break; } String message = incMsg.GetString(); outMsg.AddString(message); return true; }
private bool parseDistanceShot(NetworkMessage incMsg, NetworkMessage outMsg) { Position fromPos = incMsg.GetPosition(); outMsg.AddPosition(fromPos); Position toPos = incMsg.GetPosition(); outMsg.AddPosition(toPos); byte effect = incMsg.GetByte(); outMsg.AddByte(effect); //Map::getInstance().addDistanceEffect(fromPos, toPos, effect); return true; }
private bool parseAnimatedText(NetworkMessage incMsg, NetworkMessage outMsg) { Position textPos = incMsg.GetPosition(); outMsg.AddPosition(textPos); byte color = incMsg.GetByte(); outMsg.AddByte(color); String text = incMsg.GetString(); outMsg.AddString(text); //Map::getInstance().addAnimatedText(textPos, color, text); return true; }
private bool parseCreatureMove(NetworkMessage incMsg, NetworkMessage outMsg) { Position oldPos = incMsg.GetPosition(); outMsg.AddPosition(oldPos); byte oldStackPos = incMsg.GetByte(); outMsg.AddByte(oldStackPos); Position newPos = incMsg.GetPosition(); outMsg.AddPosition(newPos); if (oldStackPos > 9) { Logger.Log("Creature move - oldStackpos", LogType.ERROR); return false; } Tile tile = Map.GetInstance().GetTile(oldPos); if (tile == null) { Logger.Log("Creature move - !tile old", LogType.ERROR); return false; } Thing thing = tile.GetThingByStackPosition(oldStackPos); if (thing == null) { //RAISE_PROTOCOL_WARNING("Creature move - !thing"); //TODO. Notify GUI //TODO. send update tile return true; } if (!(thing is Creature)) { Logger.Log("Creature move - !creature", LogType.ERROR); return false; } Creature creature = (Creature)thing; if (!tile.RemoveThing(creature)) { Logger.Log("Creature move - removeThing", LogType.ERROR); return false; } tile = Map.GetInstance().GetTile(newPos); if (tile == null) { Logger.Log("Creature move - !tile new", LogType.ERROR); return false; } if (!tile.AddThing(creature)) { Logger.Log("Creature move - addThing", LogType.ERROR); return false; } //creature->setMoving(oldPos, newPos); //update creature direction if (oldPos.X > newPos.X) { creature.SetTurnDirection(Direction.Left); } else if (oldPos.X < newPos.X) { creature.SetTurnDirection(Direction.Right); } else if (oldPos.Y > newPos.Y) { creature.SetTurnDirection(Direction.Up); } else if (oldPos.Y < newPos.Y) { creature.SetTurnDirection(Direction.Down); } return true; }
private bool parseUpdateTile(NetworkMessage incMsg, NetworkMessage outMsg) { Position tilePos = incMsg.GetPosition(); outMsg.AddPosition(tilePos); ushort thingId = incMsg.PeekUInt16(); if (thingId == 0xFF01) { outMsg.AddUInt16(incMsg.GetUInt16()); Tile tile = Map.GetInstance().GetTile(tilePos); if (tile == null) Logger.Log("Erro ao atualizar o tile. Posição: " + tilePos.ToString(), LogType.ERROR); tile.Clear(); } else { if (!setTileDescription(incMsg, outMsg, tilePos)) Logger.Log("Erro ao atualizar o tile. Posição: " + tilePos.ToString(), LogType.ERROR); outMsg.AddUInt16(incMsg.GetUInt16()); } return true; }
private bool parseAddMapMarker(NetworkMessage incMsg, NetworkMessage outMsg) { Position myPos = incMsg.GetPosition(); outMsg.AddPosition(myPos); byte icon = incMsg.GetByte(); outMsg.AddByte(icon); String desc = incMsg.GetString(); outMsg.AddString(desc); return true; }
private bool parseTileTransformThing(NetworkMessage incMsg, NetworkMessage outMsg) { Position tilePos = incMsg.GetPosition(); outMsg.AddPosition(tilePos); byte stackPos = incMsg.GetByte(); outMsg.AddByte(stackPos); ushort thingId = incMsg.GetUInt16(); outMsg.AddUInt16(thingId); if (thingId == 0x0061 || thingId == 0x0062 || thingId == 0x0063) { //creature turn uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); byte direction = incMsg.GetByte(); outMsg.AddByte(direction); Creature creature = Creatures.GetInstance().GetCreature(creatureID); if (creature == null) { Logger.Log("Falha ao transformar o objeto. Creatura retornou nula.", LogType.ERROR); return false; } if (direction > 3) { Logger.Log("Falha ao transformar o objeto. Direção maior que 3.", LogType.ERROR); return false; } creature.SetTurnDirection((Direction)direction); } else { //get tile Tile tile = Map.GetInstance().GetTile(tilePos); if (tile == null) { Logger.Log("Falha ao transformar o objeto. Tile retornou nulo.", LogType.ERROR); return false; } //removes the old item Thing thing = tile.GetThingByStackPosition(stackPos); if (thing == null) { Logger.Log("Falha ao transformar o objeto. Objeto retornou nulo.", LogType.ERROR); return false; } if (!tile.RemoveThing(thing)) { Logger.Log("Falha ao transformar o objeto. Falha ao remover o item.", LogType.ERROR); return false; } //adds a new item Item item = internalGetItem(incMsg, outMsg, thingId); if (!tile.InsertThing(item, (int)stackPos)) { Logger.Log("Falha ao transformar o objeto. Não foi possivel inserir o item.", LogType.ERROR); return false; } } return true; }
private bool parseTileRemoveThing(NetworkMessage incMsg, NetworkMessage outMsg) { Position tilePos = incMsg.GetPosition(); outMsg.AddPosition(tilePos); byte stackPos = incMsg.GetByte(); outMsg.AddByte(stackPos); //get tile Tile tile = Map.GetInstance().GetTile(tilePos); if (tile == null) { Logger.Log("Falha ao remover o objeto. O tile retornou nulo.", LogType.ERROR); return false; } //remove thing Thing thing = tile.GetThingByStackPosition(stackPos); if (thing == null) { //RAISE_PROTOCOL_WARNING("Tile Remove - !thing"); //TODO. send update tile return true; } // NOTE (nfries88): Maybe this will fix http://otfans.net/project.php?issueid=490 if (thing is Creature) { Creature cr = (Creature)thing; cr.SetPosition(new Position(0, 0, 0)); } if (!tile.RemoveThing(thing)) { Logger.Log("Falha ao remover o objeto. Não foi possivel remover o objeto.", LogType.ERROR); return false; } return true; }
private bool parseTileAddThing(NetworkMessage incMsg, NetworkMessage outMsg) { Position tilePos = incMsg.GetPosition(); outMsg.AddPosition(tilePos); byte stack = incMsg.GetByte(); outMsg.AddByte(stack); Thing thing = internalGetThing(incMsg, outMsg); if (thing == null) { Logger.Log("Falha ao obter o objeto.", LogType.ERROR); return false; } Tile tile = Map.GetInstance().GetTile(tilePos); if (tile == null) { Logger.Log("Falha ao obter o tile.", LogType.ERROR); return false; } if (!tile.InsertThing(thing, stack)) { Logger.Log("Falha ao adicionar o objeto no tile. Posição: " + tile.GetPosition(), LogType.ERROR); return false; } Game.GetInstance().OnTileAddThing(tile, thing); return true; }
private bool parseMapDescription(NetworkMessage incMsg, NetworkMessage outMsg) { Position currentPos = incMsg.GetPosition(); outMsg.AddPosition(currentPos); GlobalVariables.SetPlayerPosition(currentPos); if (!setMapDescription(incMsg, outMsg, (int)currentPos.X - 8, (int)currentPos.Y - 6, (int)currentPos.Z, 18, 14)) { Logger.Log("Erro ao efetuar o parse da descrição do mapa. Código: 0x64", LogType.ERROR); return false; } Game.GetInstance().OnReceivePlayerMove(currentPos); return true; }
private bool parseMagicEffect(NetworkMessage incMsg, NetworkMessage outMsg) { Position effectPos = incMsg.GetPosition(); outMsg.AddPosition(effectPos); byte effect = incMsg.GetByte(); outMsg.AddByte(effect); Tile tile = Map.GetInstance().GetTile(effectPos); //Quando uma magia for lançada em um tile que não temos oque devemos fazer? //if (tile == null) //{ // Logger.Log("Magic effect - !tile", LogType.ERROR); // return false; //} //tile->addEffect(effect); return true; }