当前位置: 首页>>代码示例>>Golang>>正文


Golang utils.JsonAction函数代码示例

本文整理汇总了Golang中MonsterQuest/utils.JsonAction函数的典型用法代码示例。如果您正苦于以下问题:Golang JsonAction函数的具体用法?Golang JsonAction怎么用?Golang JsonAction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了JsonAction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: useAction

func (g *Game) useAction(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("use", "badId")
	res["message"] = "some string"
	id, ok := utils.GetIdFromJson(json) //todo
	if ok {
		p := g.players.getPlayerBySession(json["sid"].(string))
		if *consts.FEATURE {
			if p.Killed() {
				return utils.JsonAction(res["action"].(string), "killed")
			}
		}
		xParam := json["x"]
		yParam := json["y"]
		res["result"] = "badSlot"
		if xParam != nil && yParam != nil {
			if item := p.GetItem(id); item != nil && item.IsWeapon() {
				if p.IsEquippedItem(item) {
					// if item.Get
					p.SetAttackPoint(xParam.(float64), yParam.(float64))
					res["message"] = fmt.Sprintf("attack point (%f, %f)", xParam.(float64), yParam.(float64))
					res["result"] = "ok"
				}
			}
		} else {
			p.UseItem(int64(json["id"].(float64)))
			res["result"] = "ok"
		}
	}
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:30,代码来源:engine.go

示例2: destroyItem

func (g *Game) destroyItem(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("destroyItem", "badId")
	id, ok := utils.GetIdFromJson(json)
	if ok {
		item := g.items.getItem(id)
		p := g.players.getPlayerBySession(json["sid"].(string))
		if *consts.FEATURE {
			if p.Killed() {
				return utils.JsonAction(res["action"].(string), "killed")
			}
		}
		if item != nil && (item.IsOwner(p) || (!item.HasOwner() && geometry.Distance(p.GetCenter(), item.GetCenter()) <= consts.PICK_UP_RADIUS)) {
			var amount int = 1
			if json["amount"] != nil {
				amount = int(json["amount"].(float64))
			}
			// if item.GetAmount() - amount <= 0 {
			g.items.deleteItem(item)
			if item.IsOwner(p) {
				_, new_item := p.DeleteItem(item, amount)
				if new_item != nil {
					g.items.addItem(new_item)
				}
			} else if !item.HasOwner() {
				g.field.UnlinkFromCells(item)
			}
			// } else {
			//     item.DecAmount(amount)
			// }
			res["result"] = "ok"
		}
	}
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:34,代码来源:engine.go

示例3: dropItem

func (g *Game) dropItem(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("drop", "badId")
	id, ok := utils.GetIdFromJson(json)
	if ok {
		item := g.items.getItem(id)
		p := g.players.getPlayerBySession(json["sid"].(string))
		if *consts.FEATURE {
			if p.Killed() {
				return utils.JsonAction(res["action"].(string), "killed")
			}
		}
		if item != nil && item.IsOwner(p) {
			var amount int = 1
			if json["amount"] != nil {
				amount = int(json["amount"].(float64))
			}
			_, new_item := p.DropItem(item, amount)
			if new_item != nil {
				g.items.addItem(new_item)
			}
			g.field.LinkToCells(item)
			res["result"] = "ok"
		}
	}
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:26,代码来源:engine.go

示例4: pickUpItem

func (g *Game) pickUpItem(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("pickUp", "badId")
	id, ok := utils.GetIdFromJson(json)
	if ok {
		item := g.items.getItem(id)
		p := g.players.getPlayerBySession(json["sid"].(string))
		if *consts.FEATURE {
			if p.Killed() {
				return utils.JsonAction(res["action"].(string), "killed")
			}
		}
		if item != nil && !item.HasOwner() && geometry.Distance(p.GetCenter(), item.GetCenter()) <= float64(consts.PICK_UP_RADIUS) {
			if p.CanPickUp(item) {
				ok, i := p.PickUpItem(item)
				if ok {
					g.field.UnlinkFromCells(item)
					if item.GetID() != i.GetID() {
						g.items.deleteItem(item)
						item = nil
					}
					res["result"] = "ok"
				}
			} else {
				res["result"] = "tooHeavy"
			}
		}
	}
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:29,代码来源:engine.go

示例5: moveAction

func (g *Game) moveAction(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("move", "ok")
	p := g.players.getPlayerBySession(json["sid"].(string))
	if *consts.FEATURE {
		if p.Killed() {
			return utils.JsonAction(res["action"].(string), "killed")
		}
	}
	p.SetDir(consts.NameDirMapping[json["direction"].(string)])
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:11,代码来源:engine.go

示例6: setUpConstants

func (g *Game) setUpConstants(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("setUpConst", "badAction")
	if *consts.TEST && consts.TEST_MODE {
		var isValidConsts bool = true
		for name, _ := range consts.NameConstMapping {
			if json[name] != nil {
				_, ok := json[name].(float64)
				isValidConsts = isValidConsts && ok
			}
		}
		if isValidConsts {
			for name, constant := range consts.NameConstMapping {
				if json[name] != nil {
					if v, ok := constant.(*float64); ok {
						*v = json[name].(float64)
					} else if v, ok := constant.(*int); ok {
						*v = int(json[name].(float64))
					}
				}
			}
			consts.Refresh()
			res["result"] = "ok"
		}
	}
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:26,代码来源:engine.go

示例7: putItem

func (g *Game) putItem(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("putItem", "badAction")
	if *consts.TEST && consts.TEST_MODE {
		var requiredFields = map[string]string{
			"x":    "badPlacing",
			"y":    "badPlacing",
			"item": "badItem",
		}
		var ok bool
		if ok, _ = utils.CheckJsonRequest(json, requiredFields); ok {
			itemDesc, ok1 := json["item"].(map[string]interface{})
			pt, isGoodPoint := utils.GetPointFromJson(json)
			if isGoodPoint && !g.field.IsBlocked(int(pt.X), int(pt.Y)) {
				res["result"] = "badInventory"
				if ok1 {
					item := gameObjectsBase.ItemFromJson(itemDesc)
					if item != nil {
						item.ForcePlace(*geometry.MakePoint(pt.X, pt.Y))
						g.items.addItem(item)
						g.field.LinkToCells(item)
						res["id"] = item.GetID()
						res["result"] = "ok"
					}
				}
			} else {
				res["result"] = "badPlacing"
			}
		}
	}
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:31,代码来源:engine.go

示例8: equipItem

func (g *Game) equipItem(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("equip", "badId")
	id, ok := utils.GetIdFromJson(json)
	if ok {
		json["action"] = "pickUp"
		g.doPlayersAction("pickUp", json)
		res["result"] = "badSlot"
		slotParam := json["slot"]
		if slotParam != nil {
			slot, isExistSlot := consts.NameSlotMapping[slotParam.(string)]
			if isExistSlot {
				p := g.players.getPlayerBySession(json["sid"].(string))
				item := p.GetItem(id)
				if item != nil {
					reason, slots := p.Equip(item, slot)
					if reason == consts.OK {
						if slots != nil {
							res["slots"] = slots
						}
						res["result"] = "ok"
					} else if reason == consts.BADID {
						res["result"] = "badId"
					} else if reason == consts.BADSLOT {
						res["result"] = "badSlot"
					}
				} else {
					res["result"] = "badId"
				}
			}
		}
	}
	fmt.Println(res)
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:34,代码来源:engine.go

示例9: lookAction

func (g *Game) lookAction(sid string) consts.JsonType {
	res := utils.JsonAction("look", "ok")
	player := g.players.getPlayerBySession(sid)
	if player == nil {
		return nil
	}
	visibleSpaceSide := 2*(consts.VISION_RADIUS) + 1 // check this plz
	//visibleSpaceSide := 2 * (consts.VISION_RADIUS + 1)
	px, py := int(player.Center.X), int(player.Center.Y)
	visibleSpace := make([][]string, visibleSpaceSide)
	visibleObjects := make([]consts.JsonType, 0, 1000)
	var addedObjects = map[int64]bool{player.GetID(): true}
	for i := 0; i < visibleSpaceSide; i++ {
		visibleSpace[i] = make([]string, visibleSpaceSide)
		for j := 0; j < visibleSpaceSide; j++ {
			fx, fy := px-consts.VISION_RADIUS+j, py-consts.VISION_RADIUS+i
			if fx > 0 && fy > 0 && fx < g.field.Width && fy < g.field.Height {
				visibleSpace[i][j] = string(g.field.GetBackground(fx, fy))
				for id, obj := range g.field.GetObjects(fx, fy) {
					if !addedObjects[id] {
						visibleObjects = append(visibleObjects, obj.GetInfo())
						addedObjects[id] = true
					}
				}
			} else {
				visibleSpace[i][j] = string(consts.WALL_SYMBOL)
			}
		}
	}
	/*l := int(math.Max(0.0, float64(px - consts.VISION_RADIUS)))
	  r := int(math.Min(float64(g.field.Width - 1), float64(px + consts.VISION_RADIUS)))
	  t := int(math.Max(0.0, float64(py - consts.VISION_RADIUS)))
	  b := int(math.Min(float64(g.field.Height - 1), float64(py + consts.VISION_RADIUS)))
	  for i := t; i <= b; i++ {
	      for j := l; j <= r; j++ {
	          visibleSpace[i - t][j - l] = string(g.field.GetBackground(j, i))
	      }
	  }*/
	res["map"] = visibleSpace
	/*visibleObjects := make([]consts.JsonType, 0, 1000)
	  var addedObjects = map[int64] bool {player.GetID() : true}
	  for i := t; i <= b; i++ {
	      for j := l; j <= r; j++ {
	          for id, obj := range g.field.GetObjects(j, i) {
	              if !addedObjects[id] {
	                  visibleObjects = append(visibleObjects,  obj.GetInfo())
	                  addedObjects[id] = true
	              }
	          }
	      }
	  }*/
	res["actors"] = visibleObjects
	res["x"] = player.Center.X
	res["y"] = player.Center.Y
	res["health"] = player.GetHP()
	res["cur_exp"] = player.GetExp()
	res["max_exp"] = player.GetMaxExp()
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:59,代码来源:engine.go

示例10: startTesting

func (g *Game) startTesting() consts.JsonType {
	res := utils.JsonAction("startTesting", "badAction")
	if *consts.TEST && !consts.TEST_MODE {
		consts.TEST_MODE = true
		res["result"] = "ok"
	}
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:8,代码来源:engine.go

示例11: useSkillAction

func (g *Game) useSkillAction(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("useSkill", "badPoint")
	x, ok1 := json["x"].(float64)
	y, ok2 := json["y"].(float64)
	if ok1 && ok2 {
		p := g.players.getPlayerBySession(json["sid"].(string))
		if *consts.FEATURE {
			if p.Killed() {
				return utils.JsonAction(res["action"].(string), "killed")
			}
		}
		start := p.GetCenter()
		damage := p.GetCharacteristic(consts.CHARACTERISTIC_INTELLEGENCE) * consts.FIREBALL_DAMAGE_MULTIPLIER
		g.projectileManager.NewFireBallProjectile(&start, geometry.MakePoint(x, y), damage, consts.FIREBALL_RADIUS, p)
		res["result"] = "ok"
	}
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:18,代码来源:engine.go

示例12: doPlayersAction

func (g *Game) doPlayersAction(action string, json consts.JsonType) consts.JsonType {
	res := utils.JsonAction(action, "badSid")
	sid, ok := utils.GetSidFromJson(json)
	if ok {
		switch action {
		case "move":
			res = g.moveAction(json)
		case "use":
			res = g.useAction(json)
		case "getDictionary":
			res = g.getDictionaryAction()
		case "look":
			res = g.lookAction(sid)
		case "examine":
			res = g.examineAction(json)
		case "startTesting":
			res = g.startTesting()
		case "stopTesting":
			res = g.stopTesting(sid)
		case "setUpMap":
			res = g.setUpMap(json)
		case "pickUp":
			res = g.pickUpItem(json)
		case "drop":
			res = g.dropItem(json)
		case "destroyItem":
			res = g.destroyItem(json)
		case "equip":
			res = g.equipItem(json)
		case "unequip":
			res = g.unequipItem(json)
		case "moveItem":
			res = g.moveItem(json)
		case "getConst":
			res = g.getConstants()
		case "setUpConst":
			res = g.setUpConstants(json)
		case "putMob":
			res = g.putMob(json)
		case "putPlayer":
			res = g.putPlayer(json)
		case "putItem":
			res = g.putItem(json)
		case "enforce":
			res = g.enforceAction(json)
		case "setLocation":
			res = g.setLocationAction(json)
		case "useSkill":
			res = g.useSkillAction(json)
		case "revive":
			res = g.reviveAction(json)
		default:
			res = g.badAction(action)
		}
	}
	return res
}
开发者ID:koninka,项目名称:MonsterQuest,代码行数:57,代码来源:engine.go

示例13: getDictionaryAction

func (g *Game) getDictionaryAction() consts.JsonType {
	dict := make(consts.JsonType)
	for k, v := range g.dictionary {
		dict[k] = v
	}
	res := utils.JsonAction("getDictionary", "ok")
	res["dictionary"] = dict
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:9,代码来源:engine.go

示例14: setLocationAction

func (g *Game) setLocationAction(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("setLocation", "badPlacing")
	pt, ok := utils.GetPointFromJson(json)
	if ok {
		g.players.getPlayerBySession(json["sid"].(string)).ForcePlace(*pt)
		res["result"] = "ok"
	}
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:9,代码来源:engine.go

示例15: putMob

func (g *Game) putMob(json consts.JsonType) consts.JsonType {
	res := utils.JsonAction("putMob", "badAction")
	if *consts.TEST && consts.TEST_MODE {
		var requiredFields = map[string]string{
			"x":           "badPlacing",
			"y":           "badPlacing",
			"flags":       "badFlag",
			"race":        "badRace",
			"dealtDamage": "badDamage",
		}
		var ok bool
		if ok, res["result"] = utils.CheckJsonRequest(json, requiredFields); ok {
			damage, ok := json["dealtDamage"].(string)
			if ok && utils.IsDiceDesc(damage) {
				flags := json["flags"].([]interface{})
				var stats = map[string]interface{}{}
				if json["stats"] != nil {
					stats, ok = json["stats"].(map[string]interface{})
					if !ok {
						res["result"] = "badStats"
					}
				}
				var inventory = map[string]interface{}{}
				if json["inventory"] != nil {
					inventory, ok = json["inventory"].(map[string]interface{})
					if !ok {
						res["result"] = "badInventory"
					}
				}
				pt, isGoodPoint := utils.GetPointFromJson(json)
				race, isExistRace := consts.NameRaceMapping[json["race"].(string)]
				if !(isGoodPoint && g.field.FreeForObject(pt.X, pt.Y)) {
					res["result"] = "badPlacing"
				} else if !gameObjectsFlags.CheckFlags(flags) {
					res["result"] = "badFlag"
				} else if !isExistRace {
					res["result"] = "badRace"
				} else {
					m := gameObjects.NewTestMob(pt.X, pt.Y, race, damage, flags)
					if !g.setCharacteristicsToActiveObject(m, stats) {
						res["result"] = "badStats"
						return res
					}
					if !g.setInventoryToActiveObject(m, inventory) {
						res["result"] = "badInventory"
						return res
					}
					res["id"] = g.mobs.registerMob(m)
					res["result"] = "ok"
				}
			} else {
				res["result"] = "badDamage"
			}
		}
	}
	return res
}
开发者ID:apanasenko,项目名称:MonsterQuest,代码行数:57,代码来源:engine.go


注:本文中的MonsterQuest/utils.JsonAction函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。