Commit 7e8ae488 authored by 神楽坂玲奈's avatar 神楽坂玲奈

积分

parent ac5eea9f
...@@ -5,7 +5,7 @@ class DuelsController < ApplicationController ...@@ -5,7 +5,7 @@ class DuelsController < ApplicationController
# GET /duels.json # GET /duels.json
def index def index
if params[:user_id] if params[:user_id]
@user = User.find params[:user_id] @user = User.find params[:user_id]
@duels = @user.duels @duels = @user.duels
@actions = [{t('mycard.battlenet') => users_path}, @user, Duel.human_attribute_name(:index)] @actions = [{t('mycard.battlenet') => users_path}, @user, Duel.human_attribute_name(:index)]
else else
...@@ -18,7 +18,7 @@ class DuelsController < ApplicationController ...@@ -18,7 +18,7 @@ class DuelsController < ApplicationController
format.json { render json: @duels } format.json { render json: @duels }
end end
end end
# GET /duels/1 # GET /duels/1
# GET /duels/1.json # GET /duels/1.json
def show def show
...@@ -66,42 +66,46 @@ class DuelsController < ApplicationController ...@@ -66,42 +66,46 @@ class DuelsController < ApplicationController
end end
end end
@duel.winner = params[:duel][:winner_pos] == "true" ? @duel.user1 : @duel.user2 @duel.winner = params[:duel][:winner_pos] == "true" ? @duel.user1 : @duel.user2
if params[:duel][:credits] == "true"
if @duel.winner == @duel.user1 if @duel.winner == @duel.user1
if @duel.user2.credits <= 0 if @duel.user2.credits <= 0
@duel.user1_credits = 3 @duel.user1_credits = 3
@duel.user2_credits = -1 @duel.user2_credits = -1
elsif @duel.user2.credits <= 10 elsif @duel.user2.credits <= 10
@duel.user1_credits = 5 @duel.user1_credits = 5
@duel.user2_credits = -2 @duel.user2_credits = -2
else
@duel.user1_credits = 10
@duel.user2_credits = -4
end
else else
if @duel.user1.credits <= 0 @duel.user1_credits = 10
@duel.user2_credits = 3 @duel.user2_credits = -4
@duel.user1_credits = -1 end
elsif @duel.user1.credits <= 10 if params[:duel][:credits] == "false"
@duel.user2_credits = 5 @duel.user2_credits = -5
@duel.user1_credits = -2
else
@duel.user2_credits = 10
@duel.user1_credits = -4
end
end end
else else
@duel.user1_credits = 0 if @duel.user1.credits <= 0
@duel.user2_credits = 0 @duel.user2_credits = 3
@duel.user1_credits = -1
elsif @duel.user1.credits <= 10
@duel.user2_credits = 5
@duel.user1_credits = -2
else
@duel.user2_credits = 10
@duel.user1_credits = -4
end
if params[:duel][:credits] == "false"
@duel.user1_credits = -5
end
end end
if @duel.user1 if @duel.user1
@duel.user1.credits += @duel.user1_credits @duel.user1.update_attribute(:credits, @duel.user1.credits + @duel.user1_credits)
@duel.user1.save
end end
if @duel.user2 if @duel.user2
@duel.user2.credits += @duel.user2_credits @duel.user2.update_attribute(:credits, @duel.user2.credits + @duel.user2_credits)
@duel.user2.save
end end
#p @duel.user1
#p @duel.user2
#STDIN.gets
@duel.created_at = Time.zone.parse params[:duel][:created_at] @duel.created_at = Time.zone.parse params[:duel][:created_at]
respond_to do |format| respond_to do |format|
if @duel.save if @duel.save
...@@ -114,17 +118,17 @@ class DuelsController < ApplicationController ...@@ -114,17 +118,17 @@ class DuelsController < ApplicationController
end end
end end
# PUT /duels/1 # PUT /duels/1
# PUT /duels/1.json # PUT /duels/1.json
def update def update
@duel = Duel.find(params[:id]) @duel = Duel.find(params[:id])
case @current_user case @current_user
when @duel.user1 when @duel.user1
params[:duel] = {:user1_public => params[:duel][:user1_public]} params[:duel] = {:user1_public => params[:duel][:user1_public]}
when @duel.user2 when @duel.user2
params[:duel] = {:user2_public => params[:duel][:user2_public]} params[:duel] = {:user2_public => params[:duel][:user2_public]}
else else
params[:duel] = {} params[:duel] = {}
end end
respond_to do |format| respond_to do |format|
if @duel.update_attributes(params[:duel]) if @duel.update_attributes(params[:duel])
...@@ -137,8 +141,8 @@ class DuelsController < ApplicationController ...@@ -137,8 +141,8 @@ class DuelsController < ApplicationController
end end
end end
# DELETE /duels/1 # DELETE /duels/1
# DELETE /duels/1.json # DELETE /duels/1.json
def destroy def destroy
@duel = Duel.find(params[:id]) @duel = Duel.find(params[:id])
@duel.destroy @duel.destroy
...@@ -148,12 +152,13 @@ class DuelsController < ApplicationController ...@@ -148,12 +152,13 @@ class DuelsController < ApplicationController
format.json { head :no_content } format.json { head :no_content }
end end
end end
def user_deck(user_pos) def user_deck(user_pos)
@duel = Duel.find(params[:duel_id]) @duel = Duel.find(params[:duel_id])
unless (user_pos and @duel.user1_public or @duel.user1 == @current_user) or (!user_pos and @duel.user2_public or @duel.user2 == @current_user) unless (user_pos and @duel.user1_public or @duel.user1 == @current_user) or (!user_pos and @duel.user2_public or @duel.user2 == @current_user)
return respond_to do |format| return respond_to do |format|
format.ydk { redirect_to :format => :html} format.ydk { redirect_to :format => :html }
format.html{ render :text => "卡组未公开"} format.html { render :text => "卡组未公开" }
end end
end end
if user_pos if user_pos
...@@ -163,16 +168,19 @@ class DuelsController < ApplicationController ...@@ -163,16 +168,19 @@ class DuelsController < ApplicationController
main = @duel.user2_main main = @duel.user2_main
extra = @duel.user2_extra extra = @duel.user2_extra
end end
respond_to do |format| respond_to do |format|
format.html{ render :text => (["#created by ...", "#main"] + main.collect{|card|card.number} + ["#extra"] + extra.collect{|card|card.number} + ["!side"]).join("\r\n")} format.html { render :text => (["#created by ...", "#main"] + main.collect { |card| card.number } + ["#extra"] + extra.collect { |card| card.number } + ["!side"]).join("\r\n") }
format.ydk { render :text => (["#created by ...", "#main"] + main.collect{|card|card.number} + ["#extra"] + extra.collect{|card|card.number} + ["!side"]).join("\r\n")} format.ydk { render :text => (["#created by ...", "#main"] + main.collect { |card| card.number } + ["#extra"] + extra.collect { |card| card.number } + ["!side"]).join("\r\n") }
end end
end end
def user1_deck def user1_deck
user_deck(true) user_deck(true)
end end
def user2_deck def user2_deck
user_deck(false) user_deck(false)
end end
end end
...@@ -67,12 +67,12 @@ class UsersController < ApplicationController ...@@ -67,12 +67,12 @@ class UsersController < ApplicationController
@continue = params[:continue] @continue = params[:continue]
@from = params[:from].to_s.to_sym @from = params[:from].to_s.to_sym
respond_to do |format| respond_to do |format|
open("http://ygopro-ocg.com/mycard.php?key=zh99998&username=#{CGI.escape @user.name}&password=#{CGI.escape @user.password}&email=#{CGI.escape @user.email}") do |f| # open("http://ygopro-ocg.com/mycard.php?key=zh99998&username=#{CGI.escape @user.name}&password=#{CGI.escape @user.password}&email=#{CGI.escape @user.email}") do |f|
result = f.read # result = f.read
if result.to_i <= 0 # if result.to_i <= 0
@user.errors[:base] << "发生系统错误 (#{result}) 请联系zh99998@gmail.com" # @user.errors[:base] << "发生系统错误 (#{result}) 请联系zh99998@gmail.com"
end # end
end rescue @user.errors[:base] << "发生系统错误 (#{$!.inspect}) 请联系zh99998@gmail.com" # end rescue @user.errors[:base] << "发生系统错误 (#{$!.inspect}) 请联系zh99998@gmail.com"
if !@user.errors.any? and @user.save if !@user.errors.any? and @user.save
boardcast_user(@user, :"ygopro-ocg") boardcast_user(@user, :"ygopro-ocg")
session[:user_id] = @user.id session[:user_id] = @user.id
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment