require("Base/BasePanel")
RatioNumberGamePanel = Inherit(BasePanel)
local this = RatioNumberGamePanel
local dragViewListGo = {}
local roomList = {}
local triggerList = {}
local buildList = {}
local buildObjArr = {}
local curUseBuildDataArr = {}
local curCLickPos = nil
local curPlayerPos = nil
local enemyList = {}
local battleTime = Timer.New()
local battleOverTime = Timer.New()
-- local isGuide = false
startBattle = false
-- local
--初始化组件(用于子类重写)
function this:InitComponent()
this.live = nil
this.roompre = Util.GetGameObject(self.gameObject, "roomPre")
this.buildPre = Util.GetGameObject(self.gameObject, "buildPre")
this.battles = Util.GetGameObject(self.gameObject, "battle")
this.guide = Util.GetGameObject(self.gameObject, "Guide")
this.enemyPre = Util.GetGameObject(self.gameObject, "enemyPre")
this.backBtn = Util.GetGameObject(self.gameObject, "back")
this.restartGameBtn = Util.GetGameObject(self.gameObject, "restartGame")
this.playerObj = Util.GetGameObject(self.gameObject, "player")
this.lj = Util.GetGameObject(self.gameObject, "lj")
this.power = Util.GetGameObject(this.playerObj, "power"):GetComponent("Text")
this.power.color = UIColor.PURPLE
this.hj = Util.GetGameObject(this.playerObj, "hj"):GetComponent("Text")
this.bg = Util.GetGameObject(self.gameObject, "bg/bg"):GetComponent("Image")
this.failPanel = Util.GetGameObject(self.gameObject, "FailPanel")
this.failBackBtn = Util.GetGameObject(self.failPanel, "failBackBtn")
this.failResBtn = Util.GetGameObject(self.failPanel, "failResBtn")
-- this.guideImage =Util.GetGameObject(self.gameObject,"guideImg")
end
--绑定事件(用于子类重写)
function this:BindEvent()
Util.AddClick(this.backBtn, function()
UIManager.ClosePanel(UIName.RationNumberGamePanel)
UIManager.OpenPanel(UIName.RatioNumberLevelPanel)
end)
Util.AddClick(this.restartGameBtn, function()
if startBattle then
PopupTipPanel.ShowTip(Language[12546])
else
this:RestartGame()
end
end)
Util.AddClick(this.failBackBtn, function()
UIManager.ClosePanel(UIName.RationNumberGamePanel)
UIManager.OpenPanel(UIName.RatioNumberLevelPanel)
this.failPanel:SetActive(false)
end)
Util.AddClick(this.failResBtn, function()
this:RestartGame()
this.failPanel:SetActive(false)
end)
end
--添加事件监听(用于子类重写)
function this:AddListener()
end
--移除事件监听(用于子类重写)
function this:RemoveListener()
end
--界面打开时调用(用于子类重写)
function this:OnOpen(...)
-- RatioNumberManager.Init()
local bgstr = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, RatioNumberManager.playerResStr[1]).Name
this.bg.sprite = this.lspLoader:LoadSprite(bgstr)
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function this:OnShow(...)
this.failPanel:SetActive(false)
self:InitGame()
-- this.restartGameBtn:SetActive(RatioNumberManager.gameIndex>4)
-- this.backBtn:SetActive(RatioNumberManager.gameIndex>4)
-- this.failBackBtn:SetActive(RatioNumberManager.gameIndex>4)
-- this.guideImage:SetActive(false)
-- if RatioNumberManager.gameIndex == 1 then
-- isGuide = true
-- this.GuideOnce()
-- end
end
--界面层级发生改变(用于子类重写)
function this:OnSortingOrderChange()
end
--界面关闭时调用(用于子类重写)
function this:OnClose()
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
dragViewListGo = {}
end
function this:InitGame()
this:ClearBattles()
startBattle = false
curUseBuildDataArr = {}
for i = 1, #RatioNumberManager.buildIds do
local roomArr
-- local roomObjArr
local buildList = {}
-- local buildObj = {}
local buildId = RatioNumberManager.buildIds[i]
local buildInfo = ConfigManager.GetConfigData(ConfigName.CompareNumBuild, buildId)
local mod = 1
if i > 1 then
mod = 2
end
this.guide:SetActive(RatioNumberManager.chapterId == 1 and RatioNumberManager.selectLevelId == 1)
local build = self:GetBuild(mod)
build.name = "build" .. i
build.transform.localPosition = Vector2.New(-270 + (i - 1) * 540, 0)
if #buildInfo.Formula == 1 and #buildInfo.Formula[1] == 1 and i == 1 then
roomArr = {}
-- roomObjArr = {}
local room = self:GetRoom(build, 1)
-- local drageView = Util.GetGameObject(room,"DragView")
room.name = i .. "_1"
-- drageView.name = room.name
local buildTop = Util.GetGameObject(build, "top")
room.transform.localPosition = Vector2.New(0, -500)
buildTop.transform.localPosition = Vector2.New(0, -300)
Log("ratioNumber:" .. 0)
table.insert(roomArr, 0)
table.insert(buildList, roomArr)
curPlayerPos = { build = i, room = 1 }
local playerInfo = ConfigManager.GetConfigData(ConfigName.CompareNumItem, buildInfo.Formula[1][1])
local str = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, playerInfo.ResourcesId).Name;
if this.live then
this.live.gameObject:SetActive(true)
poolManager:UnLoadLive(this.live.name, this.live)
this.live = nil
end
local dieImg = Util.GetGameObject(this.playerObj, "dieImg")
dieImg:SetActive(false)
this.live = poolManager:LoadLive(str, this.playerObj.transform,
Vector3.New(playerInfo.LiveScale[1][1], playerInfo.LiveScale[1][2], playerInfo.LiveScale[1][3]),
Vector2.New(playerInfo.LiveScale[2][1], playerInfo.LiveScale[2][2]))
this.playerAnim = this.live:GetComponent("SkeletonGraphic")
this:SetPlayerInfo(curPlayerPos, 1)
this.power.text = RatioNumberManager.curPlayerPower
this.hj.text = RatioNumberManager.curPlayerHj
this.hj.gameObject:SetActive(RatioNumberManager.curPlayerHj ~= 0)
this.playerObj.transform.localPosition = Vector2.New(0, 2000)
DoTween.To(DG.Tweening.Core.DOGetter_float(function() return this.playerObj.transform.localPosition.y end),
DG.Tweening.Core.DOSetter_float(function(progress)
this.playerObj.transform.localPosition = Vector3(0, progress, 0)
end), 0, 1):SetEase(Ease.InQuad)
else
local buildTop = Util.GetGameObject(build, "top")
buildTop.transform.localPosition = Vector2.New(0, -500 + (#buildInfo.Formula * 200))
for j = 1, #buildInfo.Formula do
Log("ratioNumber:" .. j)
roomArr = {}
local room = self:GetRoom(build, 2)
-- local drageView = Util.GetGameObject(room,"DragView")
room.name = i .. "_" .. j
-- drageView.name = room.name
room.transform.localPosition = Vector2.New(0, -500 + (j - 1) * 200)
local enemyPos = Util.GetGameObject(room, "Pos/enemyPos")
local enemys = buildInfo.Formula[j]
for x = 1, #enemys do
local enemyId = enemys[x]
local enemy = this:GetEnemy(enemyId)
local x = -100 + (3 - #enemys + (x - 1)) * 100
enemy.enemy.transform:SetParent(enemyPos.transform)
enemy.enemy.transform.localPosition = Vector2.New(x, 0)
enemy.enemy.transform.localScale = Vector2.one
table.insert(roomArr, enemy)
end
table.insert(buildList, roomArr)
-- tbale.insert(roomObjArr,room)
-- table.insert(buildObj,roomObjArr)
end
end
curUseBuildDataArr[i] = buildList
-- buildObjArr[i] = buildObj
end
Log(1)
-- curUseBuildDataArr = buildDataArr
end
function this:ClearBattles()
if this.battles.transform.childCount > 0 then
for i = this.battles.transform.childCount - 1, 0, -1 do
local build = this.battles.transform:GetChild(i)
build:SetParent(this.lj.transform)
build.gameObject:SetActive(false)
end
end
end
function this:GetRoom(parent, mod)
local room
if #roomList > 0 then
room = roomList[1]
table.remove(roomList, 1)
else
room = GameObject.Instantiate(self.roompre)
local img = room:GetComponent("Image")
if mod == 1 then
img.sprite = this.lspLoader:LoadSprite(ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,
RatioNumberManager.playerResStr[3]).Name)
else
img.sprite = this.lspLoader:LoadSprite(ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,
RatioNumberManager.enemyResStr[3]).Name)
end
local playerPos = Util.GetGameObject(room, "Pos/playerPos")
local drageView = SubUIManager.Open(SubUIConfig.RationDragView, room.transform)
drageView.gameObject.name = "DragView"
drageView.gameObject:SetActive(true)
drageView:SetScrollMouse(false)
local trigger = Util.GetEventTriggerListener(drageView.gameObject)
table.insert(triggerList, trigger)
trigger.onPointerDown = trigger.onPointerDown + this.OnPointerDown
trigger.onPointerUp = trigger.onPointerUp + this.OnPointerUp
trigger.onEndDrag = trigger.onEndDrag + this.OnEndDrag
trigger.onDrag = trigger.onDrag + this.OnDrag
drageView:SetDragGO(playerPos)
end
Util.GetGameObject(room, "tips"):SetActive(false)
room.transform:SetParent(parent.transform)
room.transform.localPosition = Vector3.zero
room.transform.localScale = Vector3.one
room.gameObject:SetActive(true)
return room
end
function this:GetBuild(mod)
local build
if #buildList > 0 then
build = buildList[1]
table.remove(buildList, 1)
else
build = GameObject.Instantiate(self.buildPre)
local top = Util.GetGameObject(build, "top"):GetComponent("Image")
local down = Util.GetGameObject(build, "down"):GetComponent("Image")
local topstr
local downStr
if mod == 1 then
topstr = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, RatioNumberManager.playerResStr[4]).Name
downStr = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, RatioNumberManager.playerResStr[2])
.Name
else
topstr = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, RatioNumberManager.enemyResStr[4]).Name
downStr = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, RatioNumberManager.enemyResStr[2]).Name
end
top.sprite = this.lspLoader:LoadSprite(topstr)
down.sprite = this.lspLoader:LoadSprite(downStr)
end
build.transform:SetParent(self.battles.transform)
build.gameObject:SetActive(true)
build.transform.localPosition = Vector3.zero
build.transform.localScale = Vector3.one
return build
end
function this:GetEnemy(enemyId)
local enemyInfo = ConfigManager.GetConfigData(ConfigName.CompareNumItem, enemyId)
local enemy
if enemyList and #enemyList > 0 then
enemy = enemyList[1]
table.remove(enemyList, 1)
else
enemy = GameObject.Instantiate(this.enemyPre)
end
local powerNum = enemyInfo.CombatEffectiveness
local hjNum = 0
-- local name = Util.GetGameObject(enemy , "name"):GetComponent("Text")
local power = Util.GetGameObject(enemy, "power"):GetComponent("Text")
local hj = Util.GetGameObject(enemy, "hj"):GetComponent("Text")
power.text = powerNum
local anim = nil
local enemtStr = ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, enemyInfo.ResourcesId).Name
local zb = Util.GetGameObject(enemy, "zb"):GetComponent("Image")
local bossImg = Util.GetGameObject(enemy, "bossImg")
if enemyInfo.Type == 2 then
hj.gameObject:SetActive(false)
-- name.text = "装备"
zb.gameObject:SetActive(true)
zb.sprite = this.lspLoader:LoadSprite(enemtStr)
power.color = UIColor.PURPLE
else
power.color = UIColor.ORANGE
if enemyInfo.MonsterType == 2 then
hj.gameObject:SetActive(true)
hjNum = powerNum
hj.text = powerNum
else
hj.gameObject:SetActive(false)
end
-- name.text= str[enemyInfo.MonsterType]
local live = poolManager:LoadLive(enemtStr, enemy.transform,
Vector3.New(enemyInfo.LiveScale[1][1], enemyInfo.LiveScale[1][2], enemyInfo.LiveScale[1][3]),
Vector2.New(enemyInfo.LiveScale[2][1], enemyInfo.LiveScale[2][2]))
anim = live:GetComponent("SkeletonGraphic")
zb.gameObject:SetActive(false)
end
bossImg:SetActive(enemyInfo.DivineRing == 1)
bossImg.transform:SetSiblingIndex(enemy.transform.childCount - 1)
enemy:SetActive(true)
return {
enemy = enemy,
anim = anim,
type = enemyInfo.Type,
enemyType = enemyInfo.MonsterType,
power = powerNum,
hj =
hjNum
}
end
--拖拽
function this.OnPointerDown(Pointgo, data) --按下
Log("Click Down:" .. Pointgo.transform.parent.name)
if startBattle then
return
end
curCLickPos = this:GetPosInfo(Pointgo.transform.parent.name)
if not curCLickPos or not (curCLickPos.build == curPlayerPos.build and curCLickPos.room == curPlayerPos.room) then
curCLickPos = nil
return
end
end
function this.OnPointerUp(Pointgo, data) --抬起
if data.pointerEnter == nil then --拖到屏幕外
this:InvalidClick()
return
end
if startBattle then
return
end
Log("Click Up:" .. data.pointerEnter.transform.parent.name)
local curPos = this:GetPosInfo(data.pointerEnter.transform.parent.name)
if not curCLickPos or not curPos then
this:InvalidClick()
else
this:ValidClick(curPos)
end
-- local _j=tonumber(string.sub(Pointgo.transform.name,-1))
-- Util.Peer(Pointgo.transform,"Pos").transform:SetAsFirstSibling()
-- local heroObj=Util.GetTransform(this.gameObject,"Hero".._j)
-- heroObj:DOScale(Vector3.one * 1, 0.15)
-- heroObj.transform:SetParent(bgListGo[_j].transform)
-- heroObj.transform:SetSiblingIndex(1)--SetAsFirstSibling()
-- heroObj:GetComponent("Image").raycastTarget = false
end
function this.OnEndDrag(Pointgo, data) --结束拖动
-- Log("Click Over:"..data.pointerEnter.gameObject.transform.parent.name)
-- local _j=tonumber(string.sub(Pointgo.transform.name,-1))
-- local heroObj=Util.GetGameObject(this.gameObject,"Hero".._j)
-- if data.pointerEnter==nil then--防止拖到屏幕外
-- heroObj.transform:DOAnchorPos(Vector3.one,0)
-- heroObj.transform:SetParent(bgListGo[_j].transform)
-- heroObj.transform:SetSiblingIndex(1)
-- return
-- end
-- Log("被拖动名。。。"..Pointgo.transform.name.." ".." 进入的UI名。。。"..data.pointerEnter.gameObject.name.."")
end
function this.OnDrag(Pointgo, data) --拖动中
if startBattle then
return
end
end
function this:GetPosInfo(name)
local str = string.split(name, "_")
if #str == 2 then
local buildNum = tonumber(str[1])
local roomNum = tonumber(str[2])
return { build = buildNum, room = roomNum }
else
return nil
end
end
function this:GetPosObj(pos)
local build = Util.GetGameObject(this.battles, "build" .. pos.build)
local room = Util.GetGameObject(build, pos.build .. "_" .. pos.room)
return { build = build, room = room }
end
function this:InvalidClick()
local roomData = curUseBuildDataArr[curPlayerPos.build][curPlayerPos.room]
local index = 0
if roomData[1] == 0 then
index = 1
else
index = this:GetRoomPos(roomData)
end
this:SetPlayerPos(curPlayerPos, index)
end
function this:ValidClick(curPos)
if this:CurPosIsValid(curPos) then
local room = curUseBuildDataArr[curPos.build][curPos.room]
if room[1] == 0 then
this:InvalidClick()
else
local buildObj = this:GetPosObj(curPos).build
for i = 2, buildObj.transform.childCount - 1 do
local room = buildObj.transform:GetChild(i).gameObject
Util.GetGameObject(room, "tips"):SetActive(false)
end
if curPlayerPos.build == RatioNumberManager.enemyBuildId and curPos.build ~= RatioNumberManager.palyerBuildId and curPlayerPos.room ~= curPos.room then
this:BattleForwardLogic(curPlayerPos)
end
this:BattleLogic(curPos)
end
else
this:InvalidClick()
end
end
function this:CurPosIsValid(curPos)
local valid = false
if curPos.build ~= curPlayerPos.build then
valid = true
else
valid = this:ValidRoomIndex(curPos)
end
return valid
end
function this:ValidRoomIndex(curPos)
local buildInfo = curUseBuildDataArr[curPos.build]
local left = this:GetSelectRoomIndex(buildInfo, curPlayerPos.room - 1, -1)
local right = this:GetSelectRoomIndex(buildInfo, curPlayerPos.room + 1, 1)
if left == curPos.room or right == curPos.room or curPos.room == curPlayerPos.room then
-- this:BattleLogic(curPos)
return true
else
-- this:InvalidClick()
return false
end
end
function this:BattleLogic(curPos)
local room = curUseBuildDataArr[curPos.build][curPos.room]
local index = this:GetRoomPos(room)
local enemy = this:GetRoomEnemy(room)
SoundManager.PlayMusic(SoundConfig.BGM_RATION_LEVEL)
local battleResult = false
if enemy then
-- if RatioNumberManager.gameIndex == 1 then
-- -- isGuide = false
-- end
this.guide:SetActive(false)
startBattle = true
local power = Util.GetGameObject(enemy.enemy, "power"):GetComponent("Text")
local hj = Util.GetGameObject(enemy.enemy, "hj"):GetComponent("Text")
if enemy.type == 2 then
if enemy.enemyType == 4 then
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
enemy.power = 0
battleResult = true
elseif enemy.enemyType == 5 then
RatioNumberManager.curPlayerHj = RatioNumberManager.curPlayerHj + enemy.power
enemy.power = 0
battleResult = true
end
SoundManager.PlaySound(SoundConfig.SOUND_RATION_ZHUNAGBEI)
else
SoundManager.PlaySound(SoundConfig.SOUND_RATION_ATTACK)
battleResult = this.EnemyBattle(enemy)
end
this:SetPlayerInfo(curPos, index)
if battleTime then
battleTime:Stop()
battleTime = nil
end
local func = function()
if enemy.anim then
enemy.anim.AnimationState:SetAnimation(0, "idle", true)
if enemy.type == 2 and enemy.enemyType == 3 then
end
end
this.playerAnim.AnimationState:SetAnimation(0, "idle", true)
power.text = enemy.power
hj.text = enemy.hj
local die = not this:EnemyIsDie(enemy)
if die then
enemy.enemy.gameObject:SetActive(die)
else
if enemy.type == 1 then
local dieeffect = Util.GetGameObject(enemy.enemy, "die")
dieeffect:SetActive(true)
local time = Timer.New(function()
enemy.enemy.gameObject:SetActive(die)
dieeffect:SetActive(false)
end, 0.75)
time:Start()
else
enemy.enemy.gameObject:SetActive(false)
end
end
this.power.text = RatioNumberManager.curPlayerPower
this.hj.text = RatioNumberManager.curPlayerHj
this.hj.gameObject:SetActive(RatioNumberManager.curPlayerHj ~= 0)
curPlayerPos.build = curPos.build
curPlayerPos.room = curPos.room
if battleResult then
local arr = this:GetArrowEnemy()
if arr then
for i = 1, #arr do
local anim = arr[i]
anim.anim.AnimationState:SetAnimation(0, "attack", true)
local arrow = Util.GetGameObject(anim.enemy, "attackArr")
arrow:SetActive(true)
this.SetArrowRot(arrow)
local pos = UIManager.GetLocalPositionToTarget(anim.enemy, this.playerObj)
arrow.transform:DOLocalMove(pos, 0.5, false):OnStart(function()
end):OnComplete(function()
arrow:SetActive(false)
arrow.transform.localPosition = Vector2.one
end)
end
this.playerAnim.AnimationState:SetAnimation(0, "hit", true)
if battleOverTime then
battleOverTime:Stop()
battleOverTime = nil
end
battleOverTime = Timer.New(function()
this.power.text = RatioNumberManager.curPlayerPower
this.hj.gameObject:SetActive(RatioNumberManager.curPlayerHj ~= 0)
this.hj.text = RatioNumberManager.curPlayerHj
for i = 1, #arr do
local anim = arr[i]
anim.anim.AnimationState:SetAnimation(0, "idle", true)
end
this.playerAnim.AnimationState:SetAnimation(0, "idle", true)
if RatioNumberManager.curPlayerPower == 0 then
this:GameOverFail()
else
this:BattleOverLogic(curPos)
end
end, 0.5)
battleOverTime:Start()
else
this:BattleOverLogic(curPos)
end
else
this:GameOverFail()
end
end
battleTime = Timer.New(function()
func()
end, 1)
if enemy.anim then
this.playerAnim.AnimationState:SetAnimation(0, "attack", true)
enemy.anim.AnimationState:SetAnimation(0, "attack", true)
if enemy.type == 2 and enemy.enemyType == 3 then
local arrow = Util.GetGameObject(enemy.enemy, "attackArr")
arrow:SetActive(true)
this.SetArrowRot(arrow)
local pos = UIManager.GetLocalPositionToTarget(enemy.enemy, this.playerObj)
arrow.transform:DOLocalMove(pos, 0.5, false):OnStart(function()
end):OnComplete(function()
arrow:SetActive(false)
arrow.transform.localPosition = Vector2.one
end)
end
battleTime:Start()
else
func()
end
else
this:InvalidClick()
end
end
function this.SetArrowRot(arrow)
local targ = this.playerObj
local at = arrow
local dx = targ.transform.position.x - at.transform.transform.position.x
local dy = targ.transform.position.y - at.transform.transform.position.y
local rotationz = Mathf.Atan2(dy, dx) * 180 / Mathf.PI
rotationz = rotationz - 90
local addRotationZ = rotationz - at.transform.eulerAngles.z
if addRotationZ > 180 then
addRotationZ = addRotationZ - 360
end
at.transform.eulerAngles = Vector3.New(0, 0, at.transform.eulerAngles.z + addRotationZ);
end
function this.EnemyBattle(enemy)
local battleResult = false
if enemy.enemyType == 2 then
if enemy.hj == 0 then
if RatioNumberManager.curPlayerHj > 0 then
this.RationNum(enemy.power)
battleResult = true
if enemy.power <= RatioNumberManager.curPlayerPower then
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
enemy.power = 0
else
enemy.power = enemy.power - RatioNumberManager.curPlayerPower
end
else
if enemy.power <= RatioNumberManager.curPlayerPower then
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
enemy.power = 0
battleResult = true
end
end
else
enemy.hj = enemy.hj - RatioNumberManager.curPlayerPower
if enemy.hj < 0 then
enemy.hj = 0
end
if RatioNumberManager.curPlayerHj > 0 then
battleResult = true
this.RationNum(enemy.power)
else
if enemy.power <= RatioNumberManager.curPlayerPower then
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
battleResult = true
end
end
end
else
if enemy.enemyType == 3 then
if enemy.power <= RatioNumberManager.curPlayerPower then
battleResult = true
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
enemy.power = 0
end
else
if RatioNumberManager.curPlayerHj > 0 then
this.RationNum(enemy.power)
battleResult = true
if enemy.power <= RatioNumberManager.curPlayerPower then
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
enemy.power = 0
else
enemy.power = enemy.power - RatioNumberManager.curPlayerPower
end
else
if enemy.power <= RatioNumberManager.curPlayerPower then
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower + enemy.power
enemy.power = 0
battleResult = true
end
end
end
end
return battleResult
end
function this.RationNum(num)
RatioNumberManager.curPlayerHj = RatioNumberManager.curPlayerHj - num
if RatioNumberManager.curPlayerHj < 0 then
RatioNumberManager.curPlayerHj = 0
end
end
function this:GetArrowEnemy()
local arrow = {}
local curBuildData = curUseBuildDataArr[RatioNumberManager.enemyBuildId]
local power = 0
for i = 1, #curBuildData do
local room = curBuildData[i]
for j = 1, #room do
local enemy = room[j]
if enemy.type == 1 and enemy.enemyType == 3 and not this:EnemyIsDie(enemy) then
power = power + enemy.power
table.insert(arrow, enemy)
end
end
end
RatioNumberManager.curPlayerPower = RatioNumberManager.curPlayerPower - power
if RatioNumberManager.curPlayerPower < 0 then
RatioNumberManager.curPlayerPower = 0
end
return arrow
end
function this:BattleOverLogic(curPos)
local curBuild = curUseBuildDataArr[RatioNumberManager.enemyBuildId]
startBattle = false
for i = 1, #curBuild do
local room = curBuild[i]
if not this:RoomIsDie(room) then
local left = this:GetSelectRoomIndex(curBuild, curPos.room - 1, -1)
local right = this:GetSelectRoomIndex(curBuild, curPos.room + 1, 1)
if left then
local pos = { build = RatioNumberManager.enemyBuildId, room = left }
local obj = this:GetPosObj(pos)
Util.GetGameObject(obj.room, "tips"):SetActive(true)
end
if right then
local pos = { build = RatioNumberManager.enemyBuildId, room = right }
local obj = this:GetPosObj(pos)
Util.GetGameObject(obj.room, "tips"):SetActive(true)
end
local pos = { build = RatioNumberManager.enemyBuildId, room = curPos.room }
local obj = this:GetPosObj(pos)
Util.GetGameObject(obj.room, "tips"):SetActive(true)
return
end
end
if RatioNumberManager.enemyBuildId >= #curUseBuildDataArr then
Log("游戏胜利")
DoTween.To(DG.Tweening.Core.DOGetter_float(function() return this.playerObj.transform.localPosition.y end),
DG.Tweening.Core.DOSetter_float(function(progress)
this.playerObj.transform.localPosition = Vector3(0, progress, 0)
end), 2000, 1):SetEase(Ease.InQuad):OnComplete(function()
NetManager.CompareNumEndGameRequest(RatioNumberManager.GetCurGameInxed(), 1, function(msg)
if #msg.drop.itemlist == 0 then
PopupTipPanel.ShowTip(Language[12547])
UIManager.ClosePanel(UIName.RationNumberGamePanel)
UIManager.OpenPanel(UIName.RatioNumberLevelPanel)
else
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function()
UIManager.ClosePanel(UIName.RationNumberGamePanel)
UIManager.OpenPanel(UIName.RatioNumberLevelPanel)
end)
end
end)
end)
else
RatioNumberManager.palyerBuildId = RatioNumberManager.enemyBuildId
RatioNumberManager.enemyBuildId = RatioNumberManager.enemyBuildId + 1
RatioNumberManager.playerPower = RatioNumberManager.curPlayerPower
RatioNumberManager.PlayerHj = RatioNumberManager.curPlayerHj
this:MoveBuild()
end
end
function this:MoveBuild()
local build = this:GetPosObj(curPlayerPos)
local img = build.room:GetComponent("Image")
img.sprite = this.lspLoader:LoadSprite(ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,
RatioNumberManager.playerResStr[3]).Name)
local top = Util.GetGameObject(build.build, "top"):GetComponent("Image")
top.sprite = this.lspLoader:LoadSprite(ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,
RatioNumberManager.playerResStr[4]).Name)
startBattle = true
for i = 1, #curUseBuildDataArr do
local build = Util.GetGameObject(this.battles, "build" .. i)
DoTween.To(DG.Tweening.Core.DOGetter_float(function() return build.transform.localPosition.x end),
DG.Tweening.Core.DOSetter_float(function(progress)
build.transform.localPosition = Vector3(progress, 0, 0)
end), build.transform.localPosition.x - 540, 1):SetEase(Ease.InQuad):OnComplete(function()
if i == #curUseBuildDataArr then
startBattle = false
end
end)
end
end
function this:BattleForwardLogic(curPos)
local room = curUseBuildDataArr[curPos.build][curPos.room]
if this:RoomIsDie(room) then
local curRoomObj = this:GetPosObj(curPos)
this:AddPlayerBuilRoom(curRoomObj.room)
this:UPEnemyBuild()
end
end
function this:AddPlayerBuilRoom(room)
-- local playerBuild = curUseBuildDataArr[curPlayerPos.build]
local playerBuildObj = Util.GetGameObject(this.battles, "build" .. RatioNumberManager.palyerBuildId)
local top = Util.GetGameObject(playerBuildObj, "top")
-- local drageView = Util.GetGameObject(room,room.name)
room.transform:SetParent(playerBuildObj.transform)
room.transform.localPosition = Vector2.New(0, top.transform.localPosition.y)
room.name = RatioNumberManager.palyerBuildId .. "_" .. 1
-- drageView.name = room.name
local img = room:GetComponent("Image")
img.sprite = this.lspLoader:LoadSprite(ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig,
RatioNumberManager.playerResStr[3]).Name)
top.transform.localPosition = Vector2.New(0, top.transform.localPosition.y + 200)
end
function this:UPEnemyBuild()
local enemyBuild = curUseBuildDataArr[RatioNumberManager.enemyBuildId]
local buildObj = Util.GetGameObject(this.battles, "build" .. RatioNumberManager.enemyBuildId)
local top = Util.GetGameObject(buildObj, "top")
local index = 0
for i = 1, #enemyBuild do
local room = enemyBuild[i]
if not this:RoomIsDie(room) then
local roomObj = Util.GetGameObject(buildObj, RatioNumberManager.enemyBuildId .. "_" .. i)
roomObj.transform.localPosition = Vector2.New(0, -500 + index * 200)
index = index + 1
end
end
top.transform.localPosition = Vector2.New(0, -500 + index * 200)
end
function this:RoomIsDie(room)
for i = 1, #room do
local enemy = room[i]
if enemy.power ~= 0 or enemy.hj ~= 0 then
return false
end
end
return true
end
function this:GetRoomEnemy(room)
for i = 1, #room do
local enemy = room[i]
if not this:EnemyIsDie(enemy) then
return enemy
end
end
return nil
end
function this:GetSelectRoomIndex(build, roomId, off)
if roomId < 1 or roomId > #build then
return nil
else
local room = build[roomId]
for i = 1, #room do
local enemy = room[i]
if not this:EnemyIsDie(enemy) then
return roomId
end
end
roomId = roomId + off
return this:GetSelectRoomIndex(build, roomId, off)
end
end
function this:GetRoomPos(roomData)
for i = 1, #roomData do
local enemy = roomData[i]
if not this:EnemyIsDie(enemy) then
return (3 - #roomData + (i - 1)) - 1
end
end
return 1
end
function this:EnemyIsDie(enemy)
local isDie = true
if enemy.type == 2 then
if enemy.power > 0 then
isDie = false
end
else
if enemy.enemyType == 2 then
if enemy.hj > 0 or enemy.power > 0 then
isDie = false
end
else
if enemy.power > 0 then
isDie = false
end
end
end
return isDie
end
function this:SetPlayerPos(curPos, index)
local posObj = this:GetPosObj(curPos)
local playerPos = Util.GetGameObject(posObj.room, "Pos/playerPos")
playerPos.transform.localPosition = Vector2.New(index * 100 + -100, 0)
end
function this:SetPlayerInfo(pos, index)
local build = this:GetPosObj(pos)
local playerPos = Util.GetGameObject(build.room, "Pos/playerPos")
-- this.power.text = RatioNumberManager.curPlayerPower
this.playerObj.transform:SetParent(playerPos.transform)
this.playerObj.transform.localPosition = Vector2.zero
this:SetPlayerPos(pos, index)
end
function this:GameOverFail()
Log("游戏结束")
startBattle = false
local dieeffect = Util.GetGameObject(this.playerObj, "die")
local dieImg = Util.GetGameObject(this.playerObj, "dieImg")
this.live.gameObject:SetActive(false)
dieImg:SetActive(true)
dieeffect:SetActive(true)
local time = Timer.New(function()
NetManager.CompareNumEndGameRequest(RatioNumberManager.GetCurGameInxed(), 0, function()
this.failPanel:SetActive(true)
dieeffect:SetActive(false)
end)
end, 0.9)
time:Start()
end
function this:RestartGame()
startBattle = false
RatioNumberManager.curPlayerPower = RatioNumberManager.playerPower
RatioNumberManager.curPlayerHj = RatioNumberManager.PlayerHj
this.power.text = RatioNumberManager.curPlayerPower
this.hj.text = RatioNumberManager.curPlayerHj
this.hj.gameObject:SetActive(RatioNumberManager.curPlayerHj ~= 0)
this.playerObj.transform:SetParent(this.gameObject.transform)
local playerBuild = Util.GetGameObject(this.battles, "build" .. RatioNumberManager.palyerBuildId)
local enemyBUild = Util.GetGameObject(this.battles, "build" .. RatioNumberManager.enemyBuildId)
-- local
local dieImg = Util.GetGameObject(this.playerObj, "dieImg")
this.live.gameObject:SetActive(true)
dieImg:SetActive(false)
local newPlayerBuild = this:GetBuild(1)
newPlayerBuild.name = "build" .. RatioNumberManager.palyerBuildId
newPlayerBuild.transform.localPosition = playerBuild.transform.localPosition
enemyBUild.transform:SetParent(this.lj.transform)
playerBuild.transform:SetParent(this.lj.transform)
local newPlayerRoom = this:GetRoom(newPlayerBuild, 1)
newPlayerRoom.name = RatioNumberManager.palyerBuildId .. "_" .. 1
local buildTop = Util.GetGameObject(newPlayerBuild, "top")
newPlayerRoom.transform.localPosition = Vector2.New(0, -500)
buildTop.transform.localPosition = Vector2.New(0, -300)
curPlayerPos = { build = RatioNumberManager.palyerBuildId, room = 1 }
this:SetPlayerInfo(curPlayerPos, 1)
local newEnemyBuild = this:GetBuild(2)
newEnemyBuild.name = "build" .. RatioNumberManager.enemyBuildId
newEnemyBuild.transform.localPosition = enemyBUild.transform.localPosition
local enemyBuildTop = Util.GetGameObject(newEnemyBuild, "top")
local enemyBuildData = curUseBuildDataArr[RatioNumberManager.enemyBuildId]
local i = RatioNumberManager.enemyBuildId
local buildId = RatioNumberManager.buildIds[i]
local buildInfo = ConfigManager.GetConfigData(ConfigName.CompareNumBuild, buildId)
local curData = curUseBuildDataArr[i]
for j = 1, #enemyBuildData do
local room = self:GetRoom(newEnemyBuild, 2)
local roomdata = curData[j]
-- local drageView = Util.GetGameObject(room,"DragView")
room.name = i .. "_" .. j
-- drageView.name = room.name
room.transform.localPosition = Vector2.New(0, -500 + (j - 1) * 200)
local enemyPos = Util.GetGameObject(room, "Pos/enemyPos")
local enemys = buildInfo.Formula[j]
for x = 1, #enemys do
local enemyId = enemys[x]
local enemy = this:GetEnemy(enemyId)
local x1 = -100 + (3 - #enemys + (x - 1)) * 100
enemy.enemy.transform:SetParent(enemyPos.transform)
enemy.enemy.transform.localPosition = Vector2.New(x1, 0)
enemy.enemy.transform.localScale = Vector2.one
roomdata[x] = enemy
end
end
enemyBuildTop.transform.localPosition = Vector2.New(0, -500 + #enemyBuildData * 200)
end
-- function this.GuideOnce()
-- local playerRoom = this:GetPosObj(curPlayerPos).room
-- this.guideImage:SetActive(true)
-- this.GuideMove(playerRoom.transform.position,Vector2.New(270,-500))
-- end
-- function this.GuideMove(pos,vector)
-- this.guideImage.transform.position=pos
-- this.guideImage.transform:DOLocalMove(vector, 1, false):OnStart(function ()
-- end):OnComplete(function ()
-- if isGuide then
-- this.GuideMove(pos,vector)
-- else
-- this.guideImage:SetActive(false)
-- end
-- end)
-- end
return RatioNumberGamePanel