git-first-commit-1

This commit is contained in:
Rustam Akberov 2024-01-19 02:30:58 +03:00
parent 35dee8c902
commit 03e2a785ec
3 changed files with 7 additions and 85 deletions

View file

@ -1,5 +1,5 @@
module FightClub module FightClub
go 1.21.6 go 1.19
require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240112103746-ed7362810021

View file

@ -1,2 +1,4 @@
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 h1:N+dMIBmteXjJpkH6UZ7HmNftuFxkqszfGLbhsEctnv0= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0 h1:N+dMIBmteXjJpkH6UZ7HmNftuFxkqszfGLbhsEctnv0=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag= github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231127165613-b35f351f0ba0/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240112103746-ed7362810021 h1:ojv5usqbh/Dxe67osTxjpA5mn51TxzyTOn7fbzBHdx0=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20240112103746-ed7362810021/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag=

View file

@ -93,7 +93,6 @@ func BuyItem(playerName string, itemID int) {
} }
} }
// Добавляем проверку наличия itemID в массиве player.items
if contains(player.items, itemID) { if contains(player.items, itemID) {
panic("item has already been purchased") panic("item has already been purchased")
} }
@ -104,7 +103,6 @@ func BuyItem(playerName string, itemID int) {
oracle.Request(storeURL, filter, "cbBuyItem", playerName, 2*oracle.MinimumResponseGas) oracle.Request(storeURL, filter, "cbBuyItem", playerName, 2*oracle.MinimumResponseGas)
} }
// Функция, проверяющая наличие элемента в массиве
func contains(arr []int, item int) bool { func contains(arr []int, item int) bool {
for _, v := range arr { for _, v := range arr {
if v == item { if v == item {
@ -114,34 +112,6 @@ func contains(arr []int, item int) bool {
return false return false
} }
//func CbBuyItem(url string, userData any, code int, result []byte) {
// callingHash := runtime.GetCallingScriptHash()
// if !callingHash.Equals(oracle.Hash) {
// panic("not called from the oracle contract")
// }
// if code != oracle.Success {
// panic("request failed for " + url + " with code " + std.Itoa(code, 10))
// }
// runtime.Log("Result for " + url + " is: " + string(result))
//
// resultLen := len(result)
// data := std.JSONDeserialize(result[1 : resultLen-1]).(map[string]any)
// price := data["price"].(int)
// gearID := data["id"].(int)
// playerName := userData.(string)
//
// player := getPlayer(playerName)
// if player.balance < price {
// panic("insufficient balance")
// }
// player.balance -= price
// player.items = append(player.items, gearID)
//
// ctx := storage.GetContext()
// storage.Put(ctx, playerName, std.Serialize(player))
// runtime.Log("Item purchased successfully by " + playerName)
//}
func CbBuyItem(url string, userData any, code int, result []byte) { func CbBuyItem(url string, userData any, code int, result []byte) {
callingHash := runtime.GetCallingScriptHash() callingHash := runtime.GetCallingScriptHash()
if !callingHash.Equals(oracle.Hash) { if !callingHash.Equals(oracle.Hash) {
@ -164,7 +134,6 @@ func CbBuyItem(url string, userData any, code int, result []byte) {
} }
player.balance -= price player.balance -= price
// Вместо удаления предыдущих itemID, добавим новый itemID в инвентарь
player.items = append(player.items, gearID) player.items = append(player.items, gearID)
ctx := storage.GetContext() ctx := storage.GetContext()
@ -210,17 +179,7 @@ func getRealOpponent(playerName string) string {
} }
var opponents []string var opponents []string
//items := make([]int, 0)
//pypkaPlayer := Player{
// balance: 20,
// items: items,
// name: "Pypkaed",
// points: 5,
// speed: 0,
// stamina: 0,
// strength: 0,
//}
//opponents = append(opponents, pypkaPlayer)
for _, name := range playersList { for _, name := range playersList {
if name != playerName { if name != playerName {
opponents = append(opponents, name) opponents = append(opponents, name)
@ -246,7 +205,7 @@ func abs(x int) int {
} }
func calculateWinningChances(playerData Player, opponentData Player) int { func calculateWinningChances(playerData Player, opponentData Player) int {
chance := 50 // Default chance chance := 50
if playerData.speed != opponentData.speed { if playerData.speed != opponentData.speed {
chance += (playerData.speed - opponentData.speed) * 5 chance += (playerData.speed - opponentData.speed) * 5
@ -266,7 +225,6 @@ func calculateWinningChances(playerData Player, opponentData Player) int {
} }
func battle(playerName string, opponentName string, bet int) string { func battle(playerName string, opponentName string, bet int) string {
// Проверка наличия оппонента
if getPlayer(opponentName).name == "" { if getPlayer(opponentName).name == "" {
panic("opponent not found") panic("opponent not found")
} }
@ -274,7 +232,6 @@ func battle(playerName string, opponentName string, bet int) string {
player := getPlayer(playerName) player := getPlayer(playerName)
opponent := getPlayer(opponentName) opponent := getPlayer(opponentName)
// Проверка наличия средств у игроков для выполнения ставок
if player.balance < bet || opponent.balance < bet { if player.balance < bet || opponent.balance < bet {
panic("insufficient balance for the battle") panic("insufficient balance for the battle")
} }
@ -282,7 +239,6 @@ func battle(playerName string, opponentName string, bet int) string {
chancePlayer := calculateWinningChances(player, opponent) chancePlayer := calculateWinningChances(player, opponent)
winner := chooseWinner(chancePlayer) winner := chooseWinner(chancePlayer)
// Логирование начала боя и его результатов
runtime.Log("Battle started: " + playerName + " vs " + opponentName) runtime.Log("Battle started: " + playerName + " vs " + opponentName)
runtime.Log("Chances of " + playerName + ": " + std.Itoa(chancePlayer, 10) + "%") runtime.Log("Chances of " + playerName + ": " + std.Itoa(chancePlayer, 10) + "%")
@ -323,45 +279,10 @@ func distributeWinnings(winner, player1, player2 string, bet int) {
storage.Delete(ctx, player1) storage.Delete(ctx, player1)
storage.Delete(ctx, player2) storage.Delete(ctx, player2)
// Обновление списка игроков
UpdatePlayersList(winner) UpdatePlayersList(winner)
runtime.Log("Winnings distributed successfully.") runtime.Log("Winnings distributed successfully.")
} }
//
//func findMatch(playerName string, bet int) string {
// opponent := getRealOpponent(playerName)
// return battle(playerName, opponent, bet)
//}
//
//func findRandomMatch(playerName string, bet int) string {
// opponent := createRandomOpponent(playerName)
// return battle(playerName, opponent, bet)
//}
//
//func createRandomOpponent(playerName string) string {
// // Реализация логики создания случайного оппонента на основе очков игрока
// randomOpponentName := "RandomOpponent" + std.Itoa10(random(1000))
// return randomOpponentName
//}
// func MatchMaking(player string, bet int) {
// randomNumber := random(2)
//
// // Логирование начала поиска матча
// if randomNumber == 1 {
// runtime.Log("Searching for a match for " + player)
// winner := findMatch(player, bet)
// // Логирование победителя матча
// runtime.Log("Winner: " + winner)
// } else {
// runtime.Log("Searching for a random match for " + player)
// winner := findRandomMatch(player, bet)
// // Логирование победителя матча
// runtime.Log("Winner: " + winner)
// }
//
// }
func findMatch(playerName string, bet int) string { func findMatch(playerName string, bet int) string {
opponent := getRealOpponent(playerName) opponent := getRealOpponent(playerName)
if opponent == "" { if opponent == "" {
@ -381,10 +302,9 @@ func findRandomMatch(playerName string, bet int) string {
} }
func createRandomOpponent(playerName string) string { func createRandomOpponent(playerName string) string {
// Реализация логики создания случайного оппонента на основе очков игрока
opponents := getAllPlayers() opponents := getAllPlayers()
if len(opponents) < 2 { if len(opponents) < 2 {
return "" // Недостаточно игроков для создания случайного оппонента return ""
} }
var randomOpponentName string var randomOpponentName string