Exemple #1
0
void CPlayer::SendPlayerData()
{
	if ( IsNeedSendMsg() )
	{
		GameXY::Game_PlayerData game_msgPD;
		GetPlayerData(game_msgPD);
		SendMsg(game_msgPD);
	}	
}
/* virtual */ void CAnimation_SetPlayerVar::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
{
	Assert(unit.Anim.Anim == this);

	const char *var = this->varStr.c_str();
	const char *arg = this->argStr.c_str();
	const int playerId = ParseAnimInt(unit, this->playerStr.c_str());
	int rop = ParseAnimInt(unit, this->valueStr.c_str());
	int data = GetPlayerData(playerId, var, arg);

	switch (this->mod) {
		case modAdd:
			data += rop;
			break;
		case modSub:
			data -= rop;
			break;
		case modMul:
			data *= rop;
			break;
		case modDiv:
			if (!rop) {
				fprintf(stderr, "Division by zero in AnimationSetPlayerVar\n");
				Exit(1);
			}
			data /= rop;
			break;
		case modMod:
			if (!rop) {
				fprintf(stderr, "Division by zero in AnimationSetPlayerVar\n");
				Exit(1);
			}
			data %= rop;
			break;
		case modAnd:
			data &= rop;
			break;
		case modOr:
			data |= rop;
			break;
		case modXor:
			data ^= rop;
			break;
		case modNot:
			data = !data;
			break;
		default:
			data = rop;
	}
	rop = data;
	SetPlayerData(playerId, var, arg, rop);
}
/*
	玩家请求角色数据
*/
void PlayerMng::_RequestRoleData(IConnection* pConn, MessageHeader* pMsgHeader)
{
	ctos::RequestRoleData roleDataReq;
	roleDataReq.ParseFromString(GetProtoData(pMsgHeader));

	TRACELOG("ptname=[" << roleDataReq.ptname() << "] request role data.");

	if (roleDataReq.ptname() == "")
	{
		TRACELOG("request role data, pt name is NULL");
		return;
	}

	// 获取角色数据
	GetPlayerData(pConn, roleDataReq.ptname());
}
Exemple #4
0
/* virtual */ void CAnimation_SetPlayerVar::Action(CUnit &unit, int &/*move*/, int /*scale*/) const
{
	Assert(unit.Anim.Anim == this);

	const char *var = this->varStr.c_str();
	const char *arg = this->argStr.c_str();
	const int playerId = ParseAnimInt(&unit, this->playerStr.c_str());
	int rop = ParseAnimInt(&unit, this->valueStr.c_str());
	int data = GetPlayerData(playerId, var, arg);

	switch (this->mod) {
		case MOD_ADD:
			data += rop;
			break;
		case MOD_SUB:
			data -= rop;
			break;
		case MOD_MUL:
			data *= rop;
			break;
		case MOD_DIV:
			if (!rop) {
				fprintf(stderr, "Division by zero in AnimationSetPlayerVar\n");
				Exit(1);
			}
			data /= rop;
			break;
		case MOD_MOD:
			if (!rop) {
				fprintf(stderr, "Division by zero in AnimationSetPlayerVar\n");
				Exit(1);
			}
			data %= rop;
			break;
		default:
			data = rop;
	}
	rop = data;
	SetPlayerData(playerId, var, arg, rop);
}
int ParseAnimInt(const CUnit &unit, const char *parseint)
{
	char s[100];
	const CUnit *goal = &unit;

	if (!strlen(parseint)) {
		return 0;
	}

	strcpy(s, parseint);
	char *cur = &s[2];
	if (s[0] == 'v' || s[0] == 't') { //unit variable detected
		if (s[0] == 't') {
			if (unit.CurrentOrder()->HasGoal()) {
				goal = unit.CurrentOrder()->GetGoal();
			} else {
				return 0;
			}
		}
		char *next = strchr(cur, '.');
		if (next == NULL) {
			fprintf(stderr, "Need also specify the variable '%s' tag \n", cur);
			ExitFatal(1);
		} else {
			*next = '\0';
		}
		const int index = UnitTypeVar.VariableNameLookup[cur];// User variables
		if (index == -1) {
			if (!strcmp(cur, "ResourcesHeld")) {
				return goal->ResourcesHeld;
			} else if (!strcmp(cur, "ResourceActive")) {
				return goal->Resource.Active;
			} else if (!strcmp(cur, "_Distance")) {
				return unit.MapDistanceTo(*goal);
			}
			fprintf(stderr, "Bad variable name '%s'\n", cur);
			ExitFatal(1);
		}
		if (!strcmp(next + 1, "Value")) {
			return goal->Variable[index].Value;
		} else if (!strcmp(next + 1, "Max")) {
			return goal->Variable[index].Max;
		} else if (!strcmp(next + 1, "Increase")) {
			return goal->Variable[index].Increase;
		} else if (!strcmp(next + 1, "Enable")) {
			return goal->Variable[index].Enable;
		} else if (!strcmp(next + 1, "Percent")) {
			return goal->Variable[index].Value * 100 / goal->Variable[index].Max;
		}
		return 0;
	} else if (s[0] == 'b' || s[0] == 'g') { //unit bool flag detected
		if (s[0] == 'g') {
			if (unit.CurrentOrder()->HasGoal()) {
				goal = unit.CurrentOrder()->GetGoal();
			} else {
				return 0;
			}
		}
		const int index = UnitTypeVar.BoolFlagNameLookup[cur];// User bool flags
		if (index == -1) {
			fprintf(stderr, "Bad bool-flag name '%s'\n", cur);
			ExitFatal(1);
		}
		return goal->Type->BoolFlag[index].value;
	} else if (s[0] == 's') { //spell type detected
		Assert(goal->CurrentAction() == UnitActionSpellCast);
		const COrder_SpellCast &order = *static_cast<COrder_SpellCast *>(goal->CurrentOrder());
		const SpellType &spell = order.GetSpell();
		if (!strcmp(spell.Ident.c_str(), cur)) {
			return 1;
		}
		return 0;
	} else if (s[0] == 'S') { // check if autocast for this spell available
		const SpellType *spell = SpellTypeByIdent(cur);
		if (!spell) {
			fprintf(stderr, "Invalid spell: '%s'\n", cur);
			ExitFatal(1);
		}
		if (unit.AutoCastSpell[spell->Slot]) {
			return 1;
		}
		return 0;
	} else if (s[0] == 'p') { //player variable detected
		char *next;
		if (*cur == '(') {
			++cur;
			char *end = strchr(cur, ')');
			if (end == NULL) {
				fprintf(stderr, "ParseAnimInt: expected ')'\n");
				ExitFatal(1);
			}
			*end = '\0';
			next = end + 1;
		} else {
			next = strchr(cur, '.');
		}
		if (next == NULL) {
			fprintf(stderr, "Need also specify the %s player's property\n", cur);
			ExitFatal(1);
		} else {
			*next = '\0';
		}
		char *arg = strchr(next + 1, '.');
		if (arg != NULL) {
			*arg = '\0';
		}
		return GetPlayerData(ParseAnimPlayer(unit, cur), next + 1, arg + 1);
	} else if (s[0] == 'r') { //random value
		char *next = strchr(cur, '.');
		if (next == NULL) {
			return SyncRand(atoi(cur) + 1);
		} else {
			*next = '\0';
			const int min = atoi(cur);
			return min + SyncRand(atoi(next + 1) - min + 1);
		}
	} else if (s[0] == 'l') { //player number
		return ParseAnimPlayer(unit, cur);

	}
	// Check if we trying to parse a number
	Assert(isdigit(s[0]) || s[0] == '-');
	return atoi(parseint);
}