Exemple #1
0
/* TODO: accuracy */
int ranged_attack( entity_t *atk, int tx, int ty )
{
	weapon_t *wpn;
	int cx = atk->x, cy = atk->y;

	if( !atk->in_hand )
	{
		if( atk == player )
		{
			buf_t *msg = bufnew( "You're not wielding anything!" );
			push_message( msg );
			bufdestroy( msg );
		}
		return 0;
	}

	if( atk->in_hand->type != ITEMTYPE_WEAPON )
	{
		if( atk == player )
		{
			buf_t *msg = bufnew( "You're not wielding a weapon!" );
			push_message( msg );
			bufdestroy( msg );
		}
		return 0;
	}

	wpn = (weapon_t*)atk->in_hand->specific;

	if( wpn->type != WEAPONTYPE_HANDGUN )
	{
		if( atk == player )
		{
			buf_t *msg = bufnew( "You're not wielding a ranged weapon!" );
			push_message( msg );
			bufdestroy( msg );
		}
		return 0;
	}

	/* consume ammo */
	if( wpn->ammo_loaded >= 1 )
	{
		wpn->ammo_loaded -= 1;
	}
	else
	{
		buf_t *msg = bufnew( "The clip is empty!" );
		push_message( msg );
		bufdestroy( msg );
		return 0;
	}

	if( atk == player )
	{
		buf_t *msg = bufnew( "You shoot your weapon!" );
		push_message( msg );
		bufdestroy( msg );
	}

	while( 1 )
	{
		cx += tx;
		cy += ty;
		
		if( is_legal( cx, cy ) &&
			( dungeon[atk->z]->terrain[cx][cy]->flags & TILEFLAG_SOLID ) )
		{
			/* you hit something solid */
			break;
		}
	
		attrset( COLOR_PAIR( C_RED ) );
		mvaddch( cy+2, cx, '*' );

		entity_t *e = entity_find_by_position( cx, cy, atk->z );
		if( e )
		{
			buf_t *msg = bufprintf( "You hit the %s!", e->name->data );
			push_message( msg );
			bufdestroy( msg );

			take_damage( e, wpn );

			break;
		}
	}

	refresh();
	msleep( 100 );

	return 1;
}
Exemple #2
0
void CHARACTER::tick()
{
	if(player->force_balanced)
	{
		char buf[128];
		str_format(buf, sizeof(buf), "You were moved to %s due to team balancing", game.controller->get_team_name(team));
		game.send_broadcast(buf, player->client_id);
		
		player->force_balanced = false;
	}

	if(input.direction != 0 || input.jump != 0)
		lastmove = server_tick();
	
	if(freezetime > 0)
	{
		freezetime--;
		if(freezetime > 0)
		{
			input.direction = 0;
			input.jump = 0;
			core.hook_state = HOOK_RETRACT_START;
			game.send_emoticon(player->client_id,  11);
		}
	}
	
	core.input = input;
	core.tick(true);
	do_splash = false;
	
	core.vel.y -= tuning.gravity;

	if(col_is_water((int)(pos.x), (int)(pos.y)))
	{
		if(!is_water)
		{
			//play a cool sound
			game.create_sound(pos, SOUND_PLAYER_SPAWN);
			do_splash = true;
			game.create_explosion(pos, -1, -1, true);
		}
		core.vel.y += config.sv_water_gravity/100.0f;
		if(core.vel.x > config.sv_water_maxx/100.0f || core.vel.x < -config.sv_water_maxx/100.0f)
			core.vel.x *= config.sv_water_friction/100.0f;
		if(core.vel.y > config.sv_water_maxy/100.0f || core.vel.y < -config.sv_water_maxy/100.0f)
			core.vel.y *= config.sv_water_friction/100.0f;
		if(core.jumped >= 2)
			core.jumped = 1;
		
		if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_UP)
			core.vel.y -= config.sv_water_gain/100.0f;
		else if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_DOWN)
			core.vel.y += config.sv_water_gain/100.0f;
		else if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_LEFT)
			core.vel.x -= config.sv_water_gain/100.0f;
		else if(col_get((int)(pos.x), (int)(pos.y))&COLFLAG_WATER_RIGHT)
			core.vel.x += config.sv_water_gain/100.0f;
		
		is_water = true;
	}
	else
	{
		if(is_water)
		{
			//play another cool sound
			game.create_sound(pos, SOUND_PLAYER_SPAWN);
			do_splash = true;
			game.create_explosion(pos, -1, -1, true);
		}
		core.vel.y += tuning.gravity;
		
		is_water = false;
	}
	
	
	if(config.sv_water_oxygen)
	{
		if (is_water)
		{
			if((server_tick() % (int)(config.sv_water_oxy_drain / 1000.0f * 50)) == 0)
			{
				if(armor)
					armor--;
				else
				{
					take_damage(vec2(0,0), 1, player->client_id, WEAPON_WORLD);
					game.send_emoticon(player->client_id,  config.sv_water_oxy_emoteid);
				}
			}
		} 
		else if((server_tick() % (int)(config.sv_water_oxy_regen / 1000.0f * 50)) == 0 && armor < 10)
			armor++;
	}

	//door
	for(int i = 0; i < 16; i++)
	{
		for(int j = 0; j < game.controller->doors[i].apos_count; j++)
		{
			if(distance(pos, game.controller->doors[i].apos[j]) < 30.0f && server_tick()-game.controller->doors[i].change_tick > 50)
			{
				game.controller->doors[i].change_tick = server_tick();
				
				if(game.controller->doors[i].team == -1 || game.controller->doors[i].team == team)
				{
					game.controller->set_door(i, !game.controller->get_door(i));
					game.create_sound(pos, SOUND_WEAPON_NOAMMO);
				}
				else
				{
					game.controller->set_door(i, !game.controller->get_door(i));
					game.create_sound(pos, SOUND_WEAPON_NOAMMO);
				}
			}
		}
	}

	//race
	if(core.jumped >= 2 && config.sv_infinite_jumping || core.jumped >= 2 &&  player->jump==1)
		core.jumped = 1;
	
	if(player->emo0==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_PAIN;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo1==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_HAPPY;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo2==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_SURPRISE;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo3==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_ANGRY;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}

	if(player->emo4==true)
	{
		CHARACTER *chr = game.players[player->client_id]->get_character();
		if (chr)
		{

			chr->emote_type = EMOTE_BLINK;
			chr->emote_stop = server_tick() + server_tickspeed();

		}
	}
	
	if(player->lolsplash==true)
		game.create_death(pos, player->client_id);

	if(player->hook==1)
		core.hook_tick = 0;

	if(player->authed)
	{
		player->respawn_tick = 0.3;
		player->die_tick = 0.3;
		if(player->god==true)
		{
			health = 25;
			armor = 25;
		}
		core.hook_tick = 0;
		if(core.jumped >= 2 && player->fly==false)
		{
			game.create_explosion(pos-vec2(0.0f, 0.0f), -1, -1, true);
			game.create_sound(pos, SOUND_GRENADE_EXPLODE);
			core.jumped = 1;
			do_splash = false;
		}
		else
		{
			if(core.jumped >= 1 && player->fly==true)
			{
				if (core.triggered_events&COREEVENT_AIR_JUMP)
					core.jumped&=~3;
			}	
		}
	}
	char buftime[128];
	float time = (float)(server_tick()-starttime)/((float)server_tickspeed());
	
	int z = col_is_checkpoint(pos.x, pos.y);
	if(z && race_state == RACE_STARTED)
	{
		cp_active = z;
		cp_current[z] = time;
		cp_tick = server_tick() + server_tickspeed()*2;
	}
	if(race_state == RACE_STARTED && server_tick()-refreshtime >= server_tickspeed())
	{
		int int_time = (int)time;
		str_format(buftime, sizeof(buftime), "Current time: %d min %d sec", int_time/60, (int_time%60));
		
		if(cp_active && cp_tick > server_tick())
		{
			PLAYER_SCORE *pscore = ((GAMECONTROLLER_RACE*)game.controller)->score.search_score(player->client_id, 0, 0);
			if(pscore && pscore->cp_time[cp_active] != 0)
			{
				char tmp[128];
				float diff = cp_current[cp_active] - pscore->cp_time[cp_active];
				str_format(tmp, sizeof(tmp), "\nCheckpoint | Diff : %s%5.3f", (diff >= 0)?"+":"", diff);
				strcat(buftime, tmp);
			}
		}
		
		game.send_broadcast(buftime, player->client_id);
		refreshtime = server_tick();
	}
	if(config.sv_regen > 0 && (server_tick()%config.sv_regen) == 0 && game.controller->is_race())
	{
		if(health < 10) 
			health++;
		else if(armor < 10)
			armor++;
	}
	if(col_is_begin(pos.x,pos.y) && game.controller->is_race() && (!weapons[WEAPON_GRENADE].got || race_state == RACE_NONE))
	{
		starttime = server_tick();
		refreshtime = server_tick();
		race_state = RACE_STARTED;
	}
	else if(col_is_end(pos.x, pos.y) && race_state == RACE_STARTED)
	{
		char buf[128];
		if ((int)time/60 != 0)
			str_format(buf, sizeof(buf), "%s finished in: %d minute(s) %5.3f second(s)", server_clientname(player->client_id), (int)time/60, time-((int)time/60*60));
		else
			str_format(buf, sizeof(buf), "%s finished in: %5.3f second(s)", server_clientname(player->client_id), time-((int)time/60*60));
		game.send_chat(-1,GAMECONTEXT::CHAT_ALL, buf);

		PLAYER_SCORE *pscore = ((GAMECONTROLLER_RACE*)game.controller)->score.search_score(player->client_id, 0, 0);
		if(pscore && time - pscore->score < 0)
		{
			str_format(buf, sizeof(buf), "New record: %5.3f second(s) better", time - pscore->score);
			game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
		}

		if(time < player->score || !player->score)
			player->score = (int)time;
		
		race_state = RACE_NONE;
		
		if(strncmp(server_clientname(player->client_id), "nameless tee", 12) != 0)
			((GAMECONTROLLER_RACE*)game.controller)->score.parsePlayer(player->client_id, (float)time, cp_current, player->save_x, player->save_y, player->diff);
	}
	else if(col_is_boost((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		vec2 speedup;
		if(core.vel.x >= 0)
			speedup = vec2(core.vel.x*(((float)config.sv_speedup_mult)/10.0)+config.sv_speedup_add,core.vel.y);
		else 
			speedup = vec2(core.vel.x*(((float)config.sv_speedup_mult)/10.0)-config.sv_speedup_add,core.vel.y);
		core.vel.x = speedup.x;
		core.vel.y = speedup.y;
	}
	else if(col_is_boostR((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		if(core.vel.x >= 0)
			core.vel.x = core.vel.x*(((float)config.sv_speedup_mult)/10.0)+config.sv_speedup_add;
		else 
			core.vel.x = config.sv_speedup_add;
	}
	else if(col_is_boostL((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		if(core.vel.x <= 0)
			core.vel.x = core.vel.x*(((float)config.sv_speedup_mult)/10.0)-config.sv_speedup_add;
		else
			core.vel.x = 0-config.sv_speedup_add;
	}
	else if(col_is_boostV((int)core.pos.x, core.pos.y) && game.controller->is_race())
	{
		if(core.vel.y >= 0)
			core.vel.y = core.vel.y+config.sv_gravity_add;
		else 
			core.vel.y = core.vel.y-config.sv_jumper_add;
		
	}

	if(col_get_admin((int)pos.x, (int)pos.y)){
		if(player->authed)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for Admins.");
		}
	}

	if(col_get_wlist((int)pos.x, (int)pos.y)){
		if(player->wlist)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for Whitelist.");
		}
	}

	if(col_get_vip((int)pos.x, (int)pos.y)){
		if(player->vip || player->authed)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for VIP.");
		}
	}

	if(col_get_police((int)pos.x, (int)pos.y)){
		if(player->police || player->authed)
		  {
			  //do nothing
		  }
		else
		{
			die(player->client_id, WEAPON_WORLD);
			game.send_chat_target(player->client_id, "Only for Police.");
		}
	}

	if(player->money_save>=750)
	{
		player->account->update();
		player->money_save = 0;
	}

	if(col_get_money1((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{			
			if(player->wlist)
			{
				player->money_save += 1;			
				player->money += 1;
			}
			if(player->vip)
			{
				player->money_save += 1;			
				player->money += 1;
			}
			player->money += 1;
			player->money_save += 1;
			player->money_tick = 0;
		}

		char buf[128];
		str_format(buf, sizeof(buf), "[1]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money2((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 2;			
				player->money += 2;
			}
			if(player->vip)
			{
				player->money_save += 2;			
				player->money += 2;
			}
			player->money += 2;
			player->money_save += 2;
			player->money_tick = 0;
		}

		char buf[128];
		str_format(buf, sizeof(buf), "[2]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money5((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 5;			
				player->money += 5;
			}
			if(player->vip)
			{
				player->money_save += 5;			
				player->money += 5;
			}
			player->money += 5;
			player->money_save += 5;
			player->money_tick = 0;
		}
       
		char buf[128];
		str_format(buf, sizeof(buf), "[5]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money10((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 10;			
				player->money += 10;
			}
			if(player->vip)
			{
				player->money_save += 10;			
				player->money += 10;
			}
			player->money += 10;
			player->money_save += 10;
			player->money_tick = 0;
		}
       
		char buf[128];
		str_format(buf, sizeof(buf), "[10]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money20((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 20;			
				player->money += 20;
			}
			if(player->vip)
			{
				player->money_save += 20;			
				player->money += 20;
			}
			player->money += 20;
			player->money_save += 20;
			player->money_tick = 0;
		}
     
		char buf[128];
		str_format(buf, sizeof(buf), "[20]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_money50((int)pos.x, (int)pos.y)){	
		player->money_tick += 1;
		if(player->money_tick >= server_tickspeed())
		{
			if(player->wlist)
			{
				player->money_save += 50;			
				player->money += 50;
			}
			if(player->vip)
			{
				player->money_save += 50;			
				player->money += 50;
			}
			player->money += 50;
			player->money_save += 50;
			player->money_tick = 0;
		}

		char buf[128];
		str_format(buf, sizeof(buf), "[50]--Your Money: %d$", player->money);
        game.send_broadcast(buf, player->client_id);
	}

	if(col_get_ninjafly((int)pos.x, (int)pos.y) && !player->authed)
	{
		player->ninjalol = 1;
		weapons[WEAPON_NINJA].got = true;
		weapons[WEAPON_NINJA].ammo = -1;
		last_weapon = active_weapon;
		active_weapon = WEAPON_NINJA;
	}

	else if(col_is_gravity((int)core.pos.x, core.pos.y) && game.controller->is_race())
		core.vel.y = core.vel.y+config.sv_gravity_add;
 	else if(col_is_jumper((int)core.pos.x, core.pos.y) && game.controller->is_race())
		core.vel.y = core.vel.y-config.sv_jumper_add;

	z = col_is_teleport(pos.x, pos.y);
	if(config.sv_teleport && z && game.controller->is_race())
	{
		if(player->authed)
		{
			//do nothing
		}
		else
		{
		core.hooked_player = -1;
		core.hook_state = HOOK_RETRACTED;
		core.triggered_events |= COREEVENT_HOOK_RETRACT;
		core.hook_state = HOOK_RETRACTED;
		core.hook_pos = core.pos;
		}
		core.pos = teleport(z);
		if(config.sv_teleport_strip)
		{
			active_weapon = WEAPON_HAMMER;
			last_weapon = WEAPON_HAMMER;
			weapons[0].got = true;
			for(int i = 1; i < 5; i++)
				weapons[i].got = false;
		}
	}
	
	float phys_size = 28.0f;
	// handle death-tiles
	if(col_get((int)(pos.x+phys_size/2), (int)(pos.y-phys_size/2))&COLFLAG_DEATH ||
			col_get((int)(pos.x+phys_size/2), (int)(pos.y+phys_size/2))&COLFLAG_DEATH ||
			col_get((int)(pos.x-phys_size/2), (int)(pos.y-phys_size/2))&COLFLAG_DEATH ||
			col_get((int)(pos.x-phys_size/2), (int)(pos.y+phys_size/2))&COLFLAG_DEATH)
	{
		die(player->client_id, WEAPON_WORLD);
	}

	// handle weapons
	handle_weapons();

	player_state = input.player_state;

	// Previnput
	previnput = input;
	oldpos = core.pos;
	return;
}
Exemple #3
0
int melee_attack( entity_t *atk, entity_t *def )
{
	if( !atk->in_hand )
	{
		if( atk == player )
		{
			buf_t *msg = bufprintf( "You %s the %s.", atk->natural->attack_name, def->name->data );
			push_message( msg );
			bufdestroy( msg );
		}
		else if( def == player )
		{
			buf_t *msg = bufprintf( "The %s %ss you.", atk->name->data, atk->natural->attack_name );
			push_message( msg );
			bufdestroy( msg );
		}

		take_damage( def, atk->natural );

		return 1;
	}

	if( atk->in_hand->type != ITEMTYPE_WEAPON )
	{
		if( atk == player )
		{
			buf_t *msg = bufnew( "You're not wielding a weapon." );
			push_message( msg );
			bufdestroy( msg );
		}
		return 0;
	}

	weapon_t *wpn = (weapon_t*)atk->in_hand->specific;

	if( wpn->type != WEAPONTYPE_MELEE )
	{
		/* TODO: ranged weapons that also have melee attacks? */
		if( atk == player )
		{
			buf_t *msg = bufnew( "You're not wielding a melee weapon." );
			push_message( msg );
			bufdestroy( msg );
		}
		return 0;
	}

	if( atk == player )
	{
		buf_t *msg = bufprintf( "You hit the %s!", def->name->data );
		push_message( msg );
		bufdestroy( msg );
	}
	else if( def == player )
	{
		buf_t *msg = bufprintf( "The %s hits you!", atk->name->data );
		push_message( msg );
		bufdestroy( msg );
	}

	take_damage( def, wpn );

	return 1;
}