Class: Gs2::Stamina::Client

Inherits:
Core::AbstractClient
  • Object
show all
Defined in:
lib/gs2/stamina/Client.rb

Overview

GS2-Stamina クライアント

Author:

  • Game Server Services, Inc.

Constant Summary

@@ENDPOINT =
'stamina'
@@VARIATION =
'a'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, gs2_client_id, gs2_client_secret) ⇒ Client

コンストラクタ

Parameters:

  • region (String)

    リージョン名

  • gs2_client_id (String)

    GSIクライアントID

  • gs2_client_secret (String)

    GSIクライアントシークレット



18
19
20
# File 'lib/gs2/stamina/Client.rb', line 18

def initialize(region, gs2_client_id, gs2_client_secret)
  super(region, gs2_client_id, gs2_client_secret)
end

Class Method Details

.ENDPOINT(v = nil) ⇒ Object

デバッグ用。通常利用する必要はありません。



23
24
25
26
27
28
29
# File 'lib/gs2/stamina/Client.rb', line 23

def self.ENDPOINT(v = nil)
  if v
    @@ENDPOINT = v
  else
    return @@ENDPOINT
  end
end

.VARIATION(v = nil) ⇒ Object

デバッグ用。通常利用する必要はありません。



32
33
34
35
36
37
38
# File 'lib/gs2/stamina/Client.rb', line 32

def self.VARIATION(v = nil)
  if v
    @@VARIATION = v
  else
    return @@VARIATION
  end
end

Instance Method Details

#change_stamina(request) ⇒ Array

スタミナ値を増減させる

同一ユーザに対するスタミナ値の増減処理が衝突した場合は、後でリクエストを出した側の処理が失敗します。
そのため、同時に複数のデバイスを利用してゲームを遊んでいる際に、一斉にクエストを開始することで1回分のスタミナ消費で2回ゲームが遊べてしまう。
というような不正行為を防ぐことが出来るようになっています。

クエストに失敗した時に消費したスタミナ値を戻してあげる際や、スタミナ値の回復アイテムを利用した際などに
スタミナ値を増やす操作を行うことになりますが、その際に overflow に true を指定することで、スタミナ値の最大値を超える回復を行えます。
スタミナ値の上限を超えた部分は overflow フィールドに格納され、優先してそちらが消費されます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • staminaPoolName => スタミナプール名

    • variation => スタミナ値の増減量

    • maxValue => スタミナ値の最大値

    • overflow => スタミナ値の最大値を超えることを許容するか

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • userId => ユーザID

      • value => スタミナ値

      • overflow => 最大値を超えているスタミナ値

      • lastUpdateAt => 更新日時



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/gs2/stamina/Client.rb', line 286

def change_stamina(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('staminaPoolName'); raise ArgumentError.new(); end
  if not request['staminaPoolName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('variation'); body['variation'] = request['variation']; end
  if request.has_key?('maxValue'); body['maxValue'] = request['maxValue']; end
  if request.has_key?('overflow'); body['overflow'] = request['overflow']; end
  query = {}
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return post(
      'Gs2Stamina', 
      'ChangeStamina', 
      @@ENDPOINT, 
      @@VARIATION,
      '/staminaPool/' + request['staminaPoolName'] + '/stamina',
      body,
      query,
      header);
end

#create_stamina_pool(request) ⇒ Array

スタミナプールを作成

GS2-Staminaを利用するには、まずスタミナプールを作成する必要があります。
スタミナプールには複数のユーザのスタミナ値を格納することができます。

スタミナプールの設定として、スタミナ値の回復速度を秒単位で指定できます。
この設定値を利用して、スタミナ値の回復処理を行いつつユーザごとに最新のスタミナ値を取得することができます。

Parameters:

  • request (Array)
    • name => スタミナプール名

    • description => 説明文

    • serviceClass => サービスクラス

    • increaseInterval => スタミナの更新速度

Returns:

  • (Array)
    • item

      • staminaPoolId => スタミナプールID

      • ownerId => オーナーID

      • name => スタミナプール名

      • description => 説明文

      • serviceClass => サービスクラス

      • increaseInterval => スタミナの更新速度

      • createAt => 作成日時



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/gs2/stamina/Client.rb', line 90

def create_stamina_pool(request)
  if not request; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('name'); body['name'] = request['name']; end
  if request.has_key?('description'); body['description'] = request['description']; end
  if request.has_key?('serviceClass'); body['serviceClass'] = request['serviceClass']; end
  if request.has_key?('increaseInterval'); body['increaseInterval'] = request['increaseInterval']; end
  query = {}
  return post(
        'Gs2Stamina', 
        'CreateStaminaPool', 
        @@ENDPOINT, 
        @@VARIATION,
        '/staminaPool',
        body,
        query);
end

#delete_stamina_pool(request) ⇒ Object

スタミナプールを削除

Parameters:

  • request (Array)
    • staminaPoolName => スタミナプール名



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/gs2/stamina/Client.rb', line 209

def delete_stamina_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('staminaPoolName'); raise ArgumentError.new(); end
  if not request['staminaPoolName']; raise ArgumentError.new(); end
  query = {}
  return delete(
        'Gs2Stamina', 
        'DeleteStaminaPool', 
        @@ENDPOINT, 
        @@VARIATION,
        '/staminaPool/' + request['staminaPoolName'],
        query);
end

#describe_stamina_pool(pageToken = nil, limit = nil) ⇒ Array

スタミナプールリストを取得

Parameters:

  • pageToken (String) (defaults to: nil)

    ページトークン

  • limit (Integer) (defaults to: nil)

    取得件数

Returns:

  • (Array)
    • items

      Array
      • staminaPoolId => スタミナプールID

      • ownerId => オーナーID

      • name => スタミナプール名

      • description => 説明文

      • serviceClass => サービスクラス

      • increaseInterval => スタミナの更新速度

      • createAt => 作成日時

    • nextPageToken => 次ページトークン



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gs2/stamina/Client.rb', line 55

def describe_stamina_pool(pageToken = nil, limit = nil)
  query = {}
  if pageToken; query['pageToken'] = pageToken; end
  if limit; query['limit'] = limit; end
  return get(
        'Gs2Stamina', 
        'DescribeStaminaPool', 
        @@ENDPOINT, 
        @@VARIATION,
        '/staminaPool',
        query);
end

#describeServiceClassArray

サービスクラスリストを取得

Returns:

  • (Array)

    サービスクラス



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gs2/stamina/Client.rb', line 111

def describeServiceClass()
  query = {}
  result = get(
      'Gs2Stamina',
      'DescribeServiceClass',
      @@ENDPOINT,
      @@VARIATION,
      '/staminaPool/serviceClass',
      query);
  return result['items'];
end

#get_stamina(request) ⇒ Array

スタミナ値を取得

指定したユーザの最新のスタミナ値を取得します。
回復処理などが行われた状態の値が応答されますので、そのままゲームで利用いただけます。

accessToken には Gs2::Auth::Client::login() でログインして取得したアクセストークンを指定してください。

Parameters:

  • request (Array)
    • staminaPoolName => スタミナプール名

    • maxValue => スタミナ値の最大値

    • accessToken => アクセストークン

Returns:

  • (Array)
    • item

      • userId => ユーザID

      • value => スタミナ値

      • overflow => 最大値を超えているスタミナ値

      • lastUpdateAt => 更新日時

    • nextIncreaseTimestamp => 次回スタミナ値が回復するタイムスタンプ(unixepoch)



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/gs2/stamina/Client.rb', line 241

def get_stamina(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('staminaPoolName'); raise ArgumentError.new(); end
  if not request['staminaPoolName']; raise ArgumentError.new(); end
  if not request.has_key?('accessToken'); raise ArgumentError.new(); end
  if not request['accessToken']; raise ArgumentError.new(); end
  query = {}
  if request.has_key?('maxValue'); query['maxValue'] = request['maxValue']; end
  header = {
    'X-GS2-ACCESS-TOKEN' => request['accessToken']
  }
  return get(
      'Gs2Stamina',
      'GetStamina',
      @@ENDPOINT,
      @@VARIATION,
      '/staminaPool/' + request['staminaPoolName'] + '/stamina',
      query,
      header);
end

#get_stamina_pool(request) ⇒ Array

スタミナプールを取得

Parameters:

  • request (Array)
    • staminaPoolName => スタミナプール名

Returns:

  • (Array)
    • item

      • staminaPoolId => スタミナプールID

      • ownerId => オーナーID

      • name => スタミナプール名

      • description => 説明文

      • serviceClass => サービスクラス

      • increaseInterval => スタミナの更新速度

      • createAt => 作成日時



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/gs2/stamina/Client.rb', line 136

def get_stamina_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('staminaPoolName'); raise ArgumentError.new(); end
  if not request['staminaPoolName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Stamina',
      'GetStaminaPool',
      @@ENDPOINT,
      @@VARIATION,
      '/staminaPool/' + request['staminaPoolName'],
      query);
end

#get_stamina_pool_status(request) ⇒ Array

スタミナプールの状態を取得

Parameters:

  • request (Array)
    • staminaPoolName => スタミナプール名

Returns:

  • (Array)
    • status => 状態



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/gs2/stamina/Client.rb', line 156

def get_stamina_pool_status(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('staminaPoolName'); raise ArgumentError.new(); end
  if not request['staminaPoolName']; raise ArgumentError.new(); end
  query = {}
  return get(
      'Gs2Stamina',
      'GetStaminaPoolStatus',
      @@ENDPOINT,
      @@VARIATION,
      '/staminaPool/' + request['staminaPoolName'] + '/status',
      query);
end

#update_stamina_pool(request) ⇒ Array

スタミナプールを更新

Parameters:

  • request (Array)
    • staminaPoolName => スタミナプール名

    • description => 説明文

    • serviceClass => サービスクラス

    • increaseInterval => スタミナの更新速度

Returns:

  • (Array)
    • item

      • staminaPoolId => スタミナプールID

      • ownerId => オーナーID

      • name => スタミナプール名

      • description => 説明文

      • serviceClass => サービスクラス

      • increaseInterval => スタミナの更新速度

      • createAt => 作成日時



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gs2/stamina/Client.rb', line 186

def update_stamina_pool(request)
  if not request; raise ArgumentError.new(); end
  if not request.has_key?('staminaPoolName'); raise ArgumentError.new(); end
  if not request['staminaPoolName']; raise ArgumentError.new(); end
  body = {}
  if request.has_key?('description'); body['description'] = request['description']; end
  if request.has_key?('serviceClass'); body['serviceClass'] = request['serviceClass']; end
  if request.has_key?('increaseInterval'); body['increaseInterval'] = request['increaseInterval']; end
  query = {}
  return put(
      'Gs2Stamina',
      'UpdateStaminaPool',
      @@ENDPOINT,
      @@VARIATION,
      '/staminaPool/' + request['staminaPoolName'],
      body,
      query);
end