示例#1
0
void SGSHero::setAI(std::string& ai)
{
  HERO_AI hero_ai = HERO_AI_ATTACK;
  if (ai == "attack") {
    hero_ai = HERO_AI_ATTACK;
  } else if (ai == "defense") {
    hero_ai = HERO_AI_DEFENSE;
  } else if (ai == "stay") {
    hero_ai = HERO_AI_STAY;
  }
  setAI(hero_ai);
}
示例#2
0
void cNPC::load( char **result, UINT16 &offset )
{
	cBaseChar::load( result, offset );
	SERIAL ser;

	minDamage_ = atoi( result[offset++] );
	maxDamage_ = atoi( result[offset++] );
	tamingMinSkill_ = atoi( result[offset++] );
	summonTime_ = atoi( result[offset++] ) + uiCurrentTime;
	if( summonTime_ )
		summonTime_ += uiCurrentTime;
	additionalFlags_ = atoi( result[offset++] );
	ser = atoi( result[offset++] );
	owner_ = dynamic_cast<P_PLAYER>(FindCharBySerial( ser ));
	carve_ = result[offset++];
	spawnregion_ = result[offset++];
	stablemasterSerial_ = atoi( result[offset++] );
	lootList_ = result[offset++];
	setAI( result[offset++] );
	setWanderType( (enWanderTypes)atoi( result[offset++] ) );
	setWanderX1( atoi( result[offset++] ) );
	setWanderX2( atoi( result[offset++] ) );
	setWanderY1( atoi( result[offset++] ) );
	setWanderY2( atoi( result[offset++] ) );
	setWanderRadius( atoi( result[offset++] ) );
	setCriticalHealth( atoi( result[offset++] ) );
	spellsLow_ = atoi( result[offset++] );
	spellsHigh_ = atoi( result[offset++] );
	controlSlots_ = atoi( result[offset++] );

	npcRegisterAfterLoading( this );
	changed_ = false;

	if (!spawnregion_.isEmpty()) {
		cSpawnRegion *region = SpawnRegions::instance()->region(spawnregion_);
		if (region) {
			region->add(serial_);
		} else {
			spawnregion_ = QString::null;
		}
	}
}
示例#3
0
void cNPC::load( QSqlQuery& result, quint16& offset )
{
	cBaseChar::load( result, offset );

	summonTime_ = result.value( offset++ ).toInt() + Server::instance()->time();
	if ( summonTime_ )
		summonTime_ += Server::instance()->time();
	additionalFlags_ = result.value( offset++ ).toInt();
	ownerSerial_ = result.value( offset++ ).toInt();
	stablemasterSerial_ = result.value( offset++ ).toInt();
	setAI( result.value( offset++ ).toString() );
	setWanderType( ( enWanderTypes ) result.value( offset++ ).toInt() );
	setWanderX1( result.value( offset++ ).toInt() );
	setWanderX2( result.value( offset++ ).toInt() );
	setWanderY1( result.value( offset++ ).toInt() );
	setWanderY2( result.value( offset++ ).toInt() );
	setWanderRadius( result.value( offset++ ).toInt() );

	changed_ = false;
}
示例#4
0
void cNPC::load( cBufferedReader& reader, unsigned int version )
{
	cBaseChar::load( reader, version );

	summonTime_ = reader.readInt();
	if ( summonTime_ )
	{
		summonTime_ += Server::instance()->time();
	}
	additionalFlags_ = reader.readInt();
	ownerSerial_ = reader.readInt();
	stablemasterSerial_ = reader.readInt();
	setAI( reader.readAscii().data() );
	setWanderType( ( enWanderTypes ) reader.readByte() );
	setWanderX1( reader.readShort() );
	setWanderY1( reader.readShort() );
	setWanderX2( reader.readShort() );
	setWanderY2( reader.readShort() );
	setWanderRadius( reader.readShort() );
}
示例#5
0
void cNPC::load( char** result, Q_UINT16& offset )
{
	cBaseChar::load( result, offset );

	summonTime_ = atoi( result[offset++] ) + Server::instance()->time();
	if ( summonTime_ )
		summonTime_ += Server::instance()->time();
	additionalFlags_ = atoi( result[offset++] );
	owner_ = reinterpret_cast<P_PLAYER>( atoi( result[offset++] ) );
	stablemasterSerial_ = atoi( result[offset++] );
	setAI( result[offset++] );
	setWanderType( ( enWanderTypes ) atoi( result[offset++] ) );
	setWanderX1( atoi( result[offset++] ) );
	setWanderX2( atoi( result[offset++] ) );
	setWanderY1( atoi( result[offset++] ) );
	setWanderY2( atoi( result[offset++] ) );
	setWanderRadius( atoi( result[offset++] ) );

	changed_ = false;
}
int main()
{

        struct GameBoard theBoard;
        initialize(theBoard);
        printf("Hello, player!\nWould you like to play against the AI? (y/n)\n");
        char * ans;
        fgets (ans, 100, stdin);
    
    while ((strcmp(ans, "y") && (strcmp(ans, "n")))) {
        
        printf("Try again, that's not a valid option.\n");
        fgets(ans, 100, stdin);
    }
    
    if ((!strcmp(ans,"y"))) {
        
        printf("Okay, you'll be going first! Enter your desired column number, 1-7.\n");
        
        setAI(theBoard);
    
    }
    
    else {
    
        printf("Okay, two players it is! 0 goes first! Enter your desired column number, 1-7.\n");
        
    }

        printBoard(theBoard, true);

        // theBoard.printBoard(true);

        // string move;

        // cin >> move;

        char * move;
        fgets (move, 100, stdin);

        while (strcmp(move, "q")) {
        
        int column = atoi(move); // making it one smaller LOL THIS?

                action(theBoard, column, getIsX(theBoard));
                if (getOver(theBoard)) {

                        printf("Game over! Play again? (y/n)\n");
                        char answer[100];
                        fgets (answer, 100, stdin);

                        while ((strcmp(answer, "y") && (strcmp(answer, "n")))) { 
                                
                                printf("Try again, that's not a valid option.\n"); 
                                fgets(answer, 100, stdin);
                        }

                        if (!strcmp(answer, "n")) { return 0; }
                        if (!strcmp(answer, "y")) { main(); }

                        return 0;

                }

                fgets(move, 100, stdin);
        }

        return 0;
}
示例#7
0
// Simple setting and getting of properties for scripts and the set command.
stError *cNPC::setProperty( const QString &name, const cVariant &value )
{
	changed( TOOLTIP );
	changed_ = true;
	/*
		\property char.nextmsgtime This integer value is the next time the npc will say something.
		This property is exclusive to NPC objects.
	*/
	SET_INT_PROPERTY( "nextmsgtime", nextMsgTime_ )

	/*
		\property char.controlslots The amount of follower slots this npc will consume when owned
		by a player.
		This property is exclusive to player characters.
	*/
	else SET_INT_PROPERTY( "controlslots", controlSlots_ )

	/*
		\property char.nextguardcalltime This integer value is the next time the npc will call for a guard.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "nextguardcalltime", nextGuardCallTime_ )
	/*
		\property char.carve This string property is the id of the carve XML definition used for the corpse this NPC will leave behind.
		This property is exclusive to NPC objects.
	*/
	else SET_STR_PROPERTY( "carve", carve_ )
	/*
		\property char.spawnregion This string property is the id of the spawnregion this NPC was spawned by.
		This property is exclusive to NPC objects.
	*/
	else SET_STR_PROPERTY( "spawnregion", spawnregion_ )
	/*
		\property char.stablemaster If this integer property is not -1, the NPC won't be visible. Is is something like a container
		value for NPCs. Item and character serials are valid here. If you set the stablemaster serial, the NPC will be automatically
		removed from the map.
		This property is exclusive to NPC objects.
	*/
	else if (name == "stablemaster") {
		setStablemasterSerial(value.toInt());
		return 0;
	}

	/*
		\property char.lootlist This string is the id of the XML definition list for the loot in the corpse this NPC will leave behind.
		This property is exclusive to NPC objects.
	*/
	else SET_STR_PROPERTY( "lootlist", lootList_ )

	/*
		\property char.maxdamage The maximum damage the natural weapon of this npc can deal.
		This property is only used if the NPC doesn't use a weapon.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "maxdamage", maxDamage_ )

	/*
		\property char.mindamage The minimum damage the natural weapon of this npc can deal.
		This property is only used if the NPC doesn't use a weapon.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "mindamage", minDamage_ )

	/*
		\property char.nextmovetime This integer is the time the npc will move next.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "nextmovetime", nextMoveTime_ )

	/*
		\property char.summoned This boolean flag indicates whether the NPC was summoned and doesn't leave a corpse behind.
		This property is exclusive to NPC objects.
	*/
	else if (name == "summoned") {
		setSummoned(value.toInt() == 1);
		return 0;

	/*
		\property char.wandertype This integer is the type of wander algorithm used for this character. One of the following values is possible:
		<code>0x00 Standing
		0x01 Rectangle
		0x02 Circle
		0x03 FollowTarget
		0x04 Destination</code>
		This property is exclusive to NPC objects.
	*/
	} else if( name == "wandertype" )
	{
		setWanderType( (enWanderTypes)value.toInt() );
		return 0;
	}

	/*
		\property char.wanderx1 This integer property is either the x component of the upper left corner of the wander rectangle or the x component of the coordinate used by the Circle wandertype.
		This property is exclusive to NPC objects.
	*/
	else if( name == "fx1" || name == "wanderx1" )
	{
		setWanderX1( value.toInt() );
		return 0;
	}
	/*
		\property char.wanderx2 This integer property is the x component of the lower right corner of the wander rectangle.
		This property is exclusive to NPC objects.
	*/
	else if( name == "fx2" || name == "wanderx2" )
	{
		setWanderX2( value.toInt() );
		return 0;
	}
	/*
		\property char.wandery1 This integer property is either the y component of the upper left corner of the wander rectangle or the y component of the coordinate used by the Circle wandertype.
		This property is exclusive to NPC objects.
	*/
	else if( name == "fy1" || name == "wandery1" )
	{
		setWanderY1( value.toInt() );
		return 0;
	}
	/*
		\property char.wandery2 This integer property is the y component of the lower right corner of the wander rectangle.
		This property is exclusive to NPC objects.
	*/
	else if( name == "fy2" || name == "wandery2" )
	{
		setWanderY2( value.toInt() );
		return 0;
	}
	/*
		\property char.wanderradius This integer property is the radius of the circle used by the Circle wandertype.
		This property is exclusive to NPC objects.
	*/
	else if( name == "fz1" || name == "wanderradius" )
	{
		setWanderRadius( value.toInt() );
		return 0;
	}
	/*
		\property char.totame The required taming skill to tame this NPC.
		Please note that this skill is the float value multiplied by 10 (100.0% = 1000).
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "totame", tamingMinSkill_ )
	/*
		\property char.summontime The servertime when this summoned creature will disappear.
		If this integer value is 0, the NPC will never disappear.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "summontime", summonTime_)
	/*
		\property char.owner This is the owner of this NPC. It returns a character object or None.
		Please note that you automatically tame the NPC by setting a new owner.
		This property is exclusive to NPC objects.
	*/
	else if( name == "owner" )
	{
		P_PLAYER pOwner = dynamic_cast<P_PLAYER>(value.toChar());
		setOwner( pOwner );
		return 0;
	}

	// skill.
	else if( name.left( 6 ) == "skill." )
	{
		QString skill = name.right( name.length() - 6 );
		INT16 skillId = Skills->findSkillByDef( skill );

		if( skillId != -1 )
		{
			setSkillValue( skillId, value.toInt() );
			return 0;
		}
	}
	/*
		\property char.ai This string property is the name of the AI used by this NPC.
		This property is exclusive to NPC objects.
	*/
	else if( name == "ai" )
	{
		setAI( value.toString() );
		return 0;
	}
	else SET_INT_PROPERTY( "fleeat", criticalHealth_ )
	/*
		\property char.criticalhealth If the NPCs hitpoints fall below the percentage given in this integer property,
		he flees from his attacker if its ai supports it.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "criticalhealth", criticalHealth_ )
	/*
		\property char.spellslow This integer bitfield indicates the spells of the first 4 circles this NPC is able to
		cast without a spellbook.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "spellslow", spellsLow_ )
	/*
		\property char.spellshigh This integer bitfield indicates the spells of the last 4 circles this NPC is able to
		cast without a spellbook.
		This property is exclusive to NPC objects.
	*/
	else SET_INT_PROPERTY( "spellshigh", spellsHigh_ )
	else if( name == "spell" )
	{
		UINT8 spell = name.right( name.length() - 6 ).toShort();

		setSpell( spell, value.toInt() );
		return 0;
	// skillcap.
	} else if( name.left( 9 ) == "skillcap." ) {
		QString skill = name.right( name.length() - 9 );
		INT16 skillId = Skills->findSkillByDef( skill );

		if( skillId != -1 )
		{
			setSkillCap(skillId, value.toInt());
			return 0;
		}
	} else {
		INT16 skillId = Skills->findSkillByDef(name);

		if (skillId != -1) {
			setSkillValue(skillId, value.toInt());
			return 0;
		}
	}

	return cBaseChar::setProperty( name, value );
}