Skip to content

Commit

Permalink
* Session.cs:
Browse files Browse the repository at this point in the history
* MapScene.unity:
* MapController.cs:
* REQUEST_CHAT.cs:
* NPCACK_MAPMOVE.cs:
* CharSelectionScene.unity:

* CharSelectionController.cs: hook some other packets
  • Loading branch information
sky-danilomenezes committed Dec 15, 2020
1 parent 8d6914d commit 0363c85
Show file tree
Hide file tree
Showing 7 changed files with 555 additions and 21 deletions.
18 changes: 12 additions & 6 deletions Assets/Scenes/CharSelection/CharSelectionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Start() {
}

private void OnMapServerLoginAccepted(ushort cmd, int size, InPacket packet) {
if(packet is ZC.ACCEPT_ENTER2) {
if (packet is ZC.ACCEPT_ENTER2) {
var pkt = packet as ZC.ACCEPT_ENTER2;
var mapLoginInfo = new MapLoginInfo() {
mapname = currentMapInfo.Mapname.Split('.')[0],
Expand All @@ -36,7 +36,7 @@ private void OnMapServerLoginAccepted(ushort cmd, int size, InPacket packet) {
}

private void OnCharacterSelectionAccepted(ushort cmd, int size, InPacket packet) {
if(packet is HC.NOTIFY_ZONESVR2) {
if (packet is HC.NOTIFY_ZONESVR2) {
Core.NetworkClient.Disconnect();

currentMapInfo = packet as HC.NOTIFY_ZONESVR2;
Expand All @@ -50,12 +50,12 @@ private void OnCharacterSelectionAccepted(ushort cmd, int size, InPacket packet)
}

private void PopulateUI() {
for(var i = 0; i < currentCharactersInfo.MaxSlots; i++) {
for (var i = 0; i < currentCharactersInfo.MaxSlots; i++) {
var item = Instantiate(charSelectionItem);
item.transform.SetParent(GridLayout.transform);

var controller = item.GetComponent<CharacterCellController>();
if(i < currentCharactersInfo.Chars.Length) {
if (i < currentCharactersInfo.Chars.Length) {
controller.BindData(currentCharactersInfo.Chars[i]);
controller.OnCharacterSelected = OnCharacterSelected;
}
Expand All @@ -67,10 +67,16 @@ private void OnCharacterSelected(CharacterData character) {
}

public void OnEnterGameClicked() {
if(selectedCharacter == null) return;
if (selectedCharacter == null) return;
var charIndex = new List<CharacterData>(currentCharactersInfo.Chars).IndexOf(selectedCharacter);
if(charIndex < 0) return;
if (charIndex < 0) return;

new CH.SELECT_CHAR(charIndex).Send();
}

public void CreateChar() {
new CH.MAKE_CHAR() {
Name = "teste"
}.Send();
}
}
16 changes: 14 additions & 2 deletions Assets/Scenes/CharSelection/CharSelectionScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,19 @@ MonoBehaviour:
m_TargetGraphic: {fileID: 1486900654}
m_OnClick:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 1697507788}
m_TargetAssemblyTypeName: CharSelectionController, UnityRO
m_MethodName: CreateChar
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1486900654
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2614,7 +2626,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Button
m_Text: New Char
--- !u!222 &2081521807
CanvasRenderer:
m_ObjectHideFlags: 0
Expand Down
22 changes: 18 additions & 4 deletions Assets/Scenes/Map/MapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ public class MapController : MonoBehaviour {

private void Awake() {
var mapInfo = Core.NetworkClient.State.MapLoginInfo;
if(mapInfo == null) {
if (mapInfo == null) {
throw new Exception("Map Login info cannot be null");
}

Core.NetworkClient.HookPacket(ZC.NOTIFY_STANDENTRY9.HEADER, OnEntitySpawn);
Core.NetworkClient.HookPacket(ZC.NOTIFY_NEWENTRY9.HEADER, OnEntitySpawn);
Core.NetworkClient.HookPacket(ZC.NOTIFY_VANISH.HEADER, OnEntityVanish);
Core.NetworkClient.HookPacket(ZC.NOTIFY_MOVE.HEADER, OnEntityMovement); //Others movement
Core.NetworkClient.HookPacket(ZC.NPCACK_MAPMOVE.HEADER, OnEntityMoved);

Core.Instance.InitCamera();
Core.Instance.SetWorldLight(worldLight);
Core.Instance.BeginMapLoading(mapInfo.mapname);

var entity = Core.EntityManager.SpawnPlayer(Core.NetworkClient.State.SelectedCharacter);
Core.Session = new Session(entity);
Core.Session.SetCurrentMap(mapInfo.mapname);
Core.Session.Entity.transform.position = new Vector3(mapInfo.PosX, Core.PathFinding.GetCellHeight(mapInfo.PosX, mapInfo.PosY), mapInfo.PosY);

/**
Expand All @@ -35,6 +37,18 @@ private void Awake() {
Core.Session.Entity.SetReady(true);
}

private void OnEntityMoved(ushort cmd, int size, InPacket packet) {
if (packet is ZC.NPCACK_MAPMOVE) {
var pkt = packet as ZC.NPCACK_MAPMOVE;

if (pkt.MapName != Core.Session.CurrentMap) {
Core.Instance.BeginMapLoading(pkt.MapName);
Core.Session.SetCurrentMap(pkt.MapName);
Core.Session.Entity.transform.position = new Vector3(pkt.PosX, Core.PathFinding.GetCellHeight(pkt.PosX, pkt.PosY), pkt.PosY);
}
}
}

private void OnEntityVanish(ushort cmd, int size, InPacket packet) {
if (packet is ZC.NOTIFY_VANISH) {
var pkt = packet as ZC.NOTIFY_VANISH;
Expand All @@ -43,7 +57,7 @@ private void OnEntityVanish(ushort cmd, int size, InPacket packet) {
}

private void OnEntitySpawn(ushort cmd, int size, InPacket packet) {
if(packet is ZC.NOTIFY_NEWENTRY9) {
if (packet is ZC.NOTIFY_NEWENTRY9) {
var pkt = packet as ZC.NOTIFY_NEWENTRY9;
Core.EntityManager.Spawn(pkt.entityData);
} else if (packet is ZC.NOTIFY_STANDENTRY9) {
Expand All @@ -53,11 +67,11 @@ private void OnEntitySpawn(ushort cmd, int size, InPacket packet) {
}

private void OnEntityMovement(ushort cmd, int size, InPacket packet) {
if(packet is ZC.NOTIFY_MOVE) {
if (packet is ZC.NOTIFY_MOVE) {
var pkt = packet as ZC.NOTIFY_MOVE;

var entity = Core.EntityManager.GetEntity(pkt.GID);
if(entity == null) return;
if (entity == null) return;

entity.SetAction(SpriteMotion.Walk);
entity.StartMoving(pkt.StartPosition[0], pkt.StartPosition[1], pkt.EndPosition[0], pkt.EndPosition[1]);
Expand Down
Loading

0 comments on commit 0363c85

Please sign in to comment.