Drafted character selection.

This commit is contained in:
genxium 2023-02-12 18:20:04 +08:00
parent de16e8e8de
commit d111de0a7a
10 changed files with 2508 additions and 35 deletions

View File

@ -168,7 +168,7 @@ func (pR *Room) updateScore() {
pR.Score = calRoomScore(pR.EffectivePlayerCount, pR.Capacity, pR.State)
}
func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, session *websocket.Conn, signalToCloseConnOfThisPlayer SignalToCloseConnCbType) bool {
func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, speciesId int, session *websocket.Conn, signalToCloseConnOfThisPlayer SignalToCloseConnCbType) bool {
playerId := pPlayerFromDbInit.Id
// TODO: Any thread-safety concern for accessing "pR" here?
if RoomBattleStateIns.IDLE != pR.State && RoomBattleStateIns.WAITING != pR.State {
@ -180,7 +180,7 @@ func (pR *Room) AddPlayerIfPossible(pPlayerFromDbInit *Player, session *websocke
return false
}
defer pR.onPlayerAdded(playerId)
defer pR.onPlayerAdded(playerId, speciesId)
pPlayerFromDbInit.UdpAddr = nil
pPlayerFromDbInit.BattleUdpTunnelAddr = nil
@ -416,15 +416,6 @@ func (pR *Room) StartBattle() {
pR.RenderFrameId = 0
for _, player := range pR.Players {
speciesId := int(player.JoinIndex - 1) // FIXME: Hardcoded the values for now
if player.JoinIndex == 1 {
speciesId = 4096
}
chosenCh := battle.Characters[speciesId]
pR.CharacterConfigsArr[player.JoinIndex-1] = chosenCh
pR.SpeciesIdList[player.JoinIndex-1] = int32(speciesId)
}
Logger.Info("[StartBattle] ", zap.Any("roomId", pR.Id), zap.Any("roomState", pR.State), zap.Any("SpeciesIdList", pR.SpeciesIdList))
// Initialize the "collisionSys" as well as "RenderFrameBuffer"
@ -954,7 +945,7 @@ func (pR *Room) clearPlayerNetworkSession(playerId int32) {
}
}
func (pR *Room) onPlayerAdded(playerId int32) {
func (pR *Room) onPlayerAdded(playerId int32, speciesId int) {
pR.EffectivePlayerCount++
if 1 == pR.EffectivePlayerCount {
@ -966,8 +957,9 @@ func (pR *Room) onPlayerAdded(playerId int32) {
pR.Players[playerId].JoinIndex = int32(index) + 1
pR.JoinIndexBooleanArr[index] = true
speciesId := index // FIXME
pR.SpeciesIdList[index] = int32(speciesId)
chosenCh := battle.Characters[speciesId]
pR.CharacterConfigsArr[index] = chosenCh
pR.Players[playerId].Speed = chosenCh.Speed
// Lazily assign the initial position of "Player" for "RoomDownsyncFrame".

View File

@ -50,7 +50,17 @@ func Serve(c *gin.Context) {
boundRoomId := 0
expectedRoomId := 0
speciesId := 0
var err error
if speciesIdStr, hasSpeciesId := c.GetQuery("speciesId"); hasSpeciesId {
speciesId, err = strconv.Atoi(speciesIdStr)
if err != nil {
// TODO: Abort with specific message.
c.AbortWithStatus(http.StatusBadRequest)
return
}
}
if boundRoomIdStr, hasBoundRoomId := c.GetQuery("boundRoomId"); hasBoundRoomId {
boundRoomId, err = strconv.Atoi(boundRoomIdStr)
if err != nil {
@ -195,7 +205,7 @@ func Serve(c *gin.Context) {
if pRoom.ReAddPlayerIfPossible(pPlayer, conn, signalToCloseConnOfThisPlayer) {
playerSuccessfullyAddedToRoom = true
} else if pRoom.AddPlayerIfPossible(pPlayer, conn, signalToCloseConnOfThisPlayer) {
} else if pRoom.AddPlayerIfPossible(pPlayer, speciesId, conn, signalToCloseConnOfThisPlayer) {
playerSuccessfullyAddedToRoom = true
} else {
Logger.Warn("Failed to get:\n", zap.Any("roomId", pRoom.Id), zap.Any("playerId", playerId), zap.Any("forExpectedRoomId", expectedRoomId))
@ -219,7 +229,7 @@ func Serve(c *gin.Context) {
} else {
pRoom = tmpRoom
Logger.Info("Successfully popped:\n", zap.Any("roomId", pRoom.Id), zap.Any("forPlayerId", playerId))
res := pRoom.AddPlayerIfPossible(pPlayer, conn, signalToCloseConnOfThisPlayer)
res := pRoom.AddPlayerIfPossible(pPlayer, speciesId, conn, signalToCloseConnOfThisPlayer)
if !res {
signalToCloseConnOfThisPlayer(Constants.RetCode.PlayerNotAddableToRoom, fmt.Sprintf("AddPlayerIfPossible returns false for roomId == %v, playerId == %v!", pRoom.Id, playerId))
}

View File

@ -59,6 +59,12 @@
"__uuid__": "0ecf4a0c-0f13-42fa-a214-b4826acd8556"
}
},
{
"frame": 0.3,
"value": {
"__uuid__": "cabf9cb6-99ca-426d-9a23-95cdec6f06b9"
}
},
{
"frame": 0.3333333333333333,
"value": {

File diff suppressed because it is too large Load Diff

View File

@ -461,7 +461,7 @@
"array": [
0,
0,
216.50635094610968,
223.42897822823446,
0,
0,
0,

View File

@ -547,7 +547,7 @@
"array": [
0,
0,
216.05530045313827,
209.61049002258042,
0,
0,
0,

View File

@ -0,0 +1,41 @@
cc.Class({
extends: cc.Component,
properties: {
panelNode: {
type: cc.Node,
default: null
},
chosenFlag: {
type: cc.Sprite,
default: null
},
avatarNode: {
type: cc.Button,
default: null
},
animNode: {
type: cc.Node,
default: null
},
speciesId: {
type: cc.Integer,
default: 0
},
},
ctor() {},
setInteractable(enabled) {
this.avatarNode.interactable = enabled;
},
onLoad() {
const avatarNodeClickEventHandler = new cc.Component.EventHandler();
avatarNodeClickEventHandler.target = this.panelNode;
avatarNodeClickEventHandler.component = "GameRule";
avatarNodeClickEventHandler.handler = "onSpeciesSelected";
avatarNodeClickEventHandler.customEventData = this.speciesId;
this.avatarNode.clickEvents.push(avatarNodeClickEventHandler);
},
});

View File

@ -0,0 +1,9 @@
{
"ver": "1.0.5",
"uuid": "6dd2c047-fa5c-4080-8221-27fabfd275d6",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}

View File

@ -10,15 +10,29 @@ cc.Class({
type: cc.Node,
default: null
},
characterSelectCells: {
type: cc.Node,
default: []
},
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
const modeBtnClickEventHandler = new cc.Component.EventHandler();
modeBtnClickEventHandler.target = this.mapNode;
modeBtnClickEventHandler.target = this.mapNode;
modeBtnClickEventHandler.component = "Map";
modeBtnClickEventHandler.handler = "onGameRule1v1ModeClicked";
this.modeButton.clickEvents.push(modeBtnClickEventHandler);
}
},
onSpeciesSelected(val) {
for (let cell of this.characterSelectCells) {
const comp = cell.getComponent("CharacterSelectCell");
if (cell.speciesId != val) {
cell.chosenFlag.active = false;
} else {
cell.chosenFlag.active = true;
}
}
},
});

View File

@ -1,3 +1,5 @@
# TODO: For websocket traffic, use a "consistent hash" on "expectedRoomId" and "boundRoomId"!
server {
listen 80;
server_name tsrht.lokcol.com;