repo_id stringlengths 6 101 | file_path stringlengths 2 269 | content stringlengths 367 5.14M | size int64 367 5.14M | filename stringlengths 1 248 | ext stringlengths 0 87 | lang stringclasses 88 values | program_lang stringclasses 232 values | doc_type stringclasses 5 values | quality_signal stringlengths 2 1.9k | effective stringclasses 2 values | hit_map stringlengths 2 1.4k |
|---|---|---|---|---|---|---|---|---|---|---|---|
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AmuletScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Amulet;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.utils.Random;
public class AmuletScene extends PixelScene {
private static final int WIDTH = 120;
private static final int BTN_HEIGHT = 18;
private static final float SMALL_GAP = 2;
private static final float LARGE_GAP = 8;
public static boolean noText = false;
private Image amulet;
@Override
public void create() {
super.create();
RenderedTextBlock text = null;
if (!noText) {
text = renderTextBlock( Messages.get(this, "text"), 8 );
text.maxWidth(WIDTH);
add( text );
}
amulet = new Image( Assets.AMULET );
add( amulet );
RedButton btnExit = new RedButton( Messages.get(this, "exit") ) {
@Override
protected void onClick() {
Dungeon.win( Amulet.class );
Dungeon.deleteGame( GamesInProgress.curSlot, true );
Game.switchScene( RankingsScene.class );
}
};
btnExit.setSize( WIDTH, BTN_HEIGHT );
add( btnExit );
RedButton btnStay = new RedButton( Messages.get(this, "stay") ) {
@Override
protected void onClick() {
onBackPressed();
}
};
btnStay.setSize( WIDTH, BTN_HEIGHT );
add( btnStay );
float height;
if (noText) {
height = amulet.height + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = (Camera.main.height - height) / 2;
align(amulet);
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, amulet.y + amulet.height + LARGE_GAP );
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
} else {
height = amulet.height + LARGE_GAP + text.height() + LARGE_GAP + btnExit.height() + SMALL_GAP + btnStay.height();
amulet.x = (Camera.main.width - amulet.width) / 2;
amulet.y = (Camera.main.height - height) / 2;
align(amulet);
text.setPos((Camera.main.width - text.width()) / 2, amulet.y + amulet.height + LARGE_GAP);
align(text);
btnExit.setPos( (Camera.main.width - btnExit.width()) / 2, text.top() + text.height() + LARGE_GAP );
btnStay.setPos( btnExit.left(), btnExit.bottom() + SMALL_GAP );
}
new Flare( 8, 48 ).color( 0xFFDDBB, true ).show( amulet, 0 ).angularSpeed = +30;
fadeIn();
}
@Override
protected void onBackPressed() {
InterlevelScene.mode = InterlevelScene.Mode.CONTINUE;
Game.switchScene( InterlevelScene.class );
}
private float timer = 0;
@Override
public void update() {
super.update();
if ((timer -= Game.elapsed) < 0) {
timer = Random.Float( 0.5f, 5f );
Speck star = (Speck)recycle( Speck.class );
star.reset( 0, amulet.x + 10.5f, amulet.y + 5.5f, Speck.DISCOVER );
add( star );
}
}
}
| 4,113 | AmuletScene | java | en | java | code | {"qsc_code_num_words": 512, "qsc_code_num_chars": 4113.0, "qsc_code_mean_word_length": 5.67578125, "qsc_code_frac_words_unique": 0.34960938, "qsc_code_frac_chars_top_2grams": 0.04026153, "qsc_code_frac_chars_top_3grams": 0.13076394, "qsc_code_frac_chars_top_4grams": 0.13626979, "qsc_code_frac_chars_dupe_5grams": 0.31245699, "qsc_code_frac_chars_dupe_6grams": 0.18857536, "qsc_code_frac_chars_dupe_7grams": 0.16930489, "qsc_code_frac_chars_dupe_8grams": 0.16930489, "qsc_code_frac_chars_dupe_9grams": 0.12525809, "qsc_code_frac_chars_dupe_10grams": 0.12525809, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01466706, "qsc_code_frac_chars_whitespace": 0.1711646, "qsc_code_size_file_byte": 4113.0, "qsc_code_num_lines": 132.0, "qsc_code_num_chars_line_max": 117.0, "qsc_code_num_chars_line_mean": 31.15909091, "qsc_code_frac_chars_alphabet": 0.83778234, "qsc_code_frac_chars_comments": 0.18988573, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.19318182, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00360144, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00240096, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06818182, "qsc_codejava_score_lines_no_logic": 0.25, "qsc_codejava_frac_words_no_modifier": 0.71428571, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/AboutScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Image;
import com.watabou.noosa.TouchArea;
import com.watabou.utils.DeviceCompat;
public class AboutScene extends PixelScene {
private static final String TTL_SHPX = "Shattered Pixel Dungeon";
private static final String TXT_SHPX =
"Design, Code, & Graphics: Evan";
private static final String LNK_SHPX = "ShatteredPixel.com";
private static final String TTL_WATA = "Pixel Dungeon";
private static final String TXT_WATA =
"Code & Graphics: Watabou\n" +
"Music: Cube_Code";
private static final String LNK_WATA = "pixeldungeon.watabou.ru";
@Override
public void create() {
super.create();
final float colWidth = Camera.main.width / (SPDSettings.landscape() ? 2 : 1);
final float colTop = (Camera.main.height / 2) - (SPDSettings.landscape() ? 30 : 90);
final float wataOffset = SPDSettings.landscape() ? colWidth : 0;
Image shpx = Icons.SHPX.get();
shpx.x = (colWidth - shpx.width()) / 2;
shpx.y = colTop;
align(shpx);
add( shpx );
new Flare( 7, 64 ).color( 0x225511, true ).show( shpx, 0 ).angularSpeed = +20;
RenderedTextBlock shpxtitle = renderTextBlock( TTL_SHPX, 8 );
shpxtitle.hardlight( Window.SHPX_COLOR );
add( shpxtitle );
shpxtitle.setPos(
(colWidth - shpxtitle.width()) / 2,
shpx.y + shpx.height + 5
);
align(shpxtitle);
RenderedTextBlock shpxtext = renderTextBlock( TXT_SHPX, 8 );
shpxtext.maxWidth((int)Math.min(colWidth, 120));
add( shpxtext );
shpxtext.setPos((colWidth - shpxtext.width()) / 2, shpxtitle.bottom() + 12);
align(shpxtext);
RenderedTextBlock shpxlink = renderTextBlock( LNK_SHPX, 8 );
shpxlink.maxWidth(shpxtext.maxWidth());
shpxlink.hardlight( Window.SHPX_COLOR );
add( shpxlink );
shpxlink.setPos((colWidth - shpxlink.width()) / 2, shpxtext.bottom() + 6);
align(shpxlink);
TouchArea shpxhotArea = new TouchArea( shpxlink.left(), shpxlink.top(), shpxlink.width(), shpxlink.height() ) {
@Override
protected void onClick( NoosaInputProcessor.Touch touch ) {
DeviceCompat.openURI("https://" + LNK_SHPX);
}
};
add( shpxhotArea );
Image wata = Icons.WATA.get();
wata.x = wataOffset + (colWidth - wata.width()) / 2;
wata.y = SPDSettings.landscape() ?
colTop:
shpxlink.top() + wata.height + 20;
align(wata);
add( wata );
new Flare( 7, 64 ).color( 0x112233, true ).show( wata, 0 ).angularSpeed = +20;
RenderedTextBlock wataTitle = renderTextBlock( TTL_WATA, 8 );
wataTitle.hardlight(Window.TITLE_COLOR);
add( wataTitle );
wataTitle.setPos(
wataOffset + (colWidth - wataTitle.width()) / 2,
wata.y + wata.height + 11
);
align(wataTitle);
RenderedTextBlock wataText = renderTextBlock( TXT_WATA, 8 );
wataText.maxWidth((int)Math.min(colWidth, 120));
wataText.setHightlighting(false); //underscore in cube_code
add( wataText );
wataText.setPos(wataOffset + (colWidth - wataText.width()) / 2, wataTitle.bottom() + 12);
align(wataText);
RenderedTextBlock wataLink = renderTextBlock( LNK_WATA, 8 );
wataLink.maxWidth((int)Math.min(colWidth, 120));
wataLink.hardlight(Window.TITLE_COLOR);
add(wataLink);
wataLink.setPos(wataOffset + (colWidth - wataLink.width()) / 2 , wataText.bottom() + 6);
align(wataLink);
TouchArea hotArea = new TouchArea( wataLink.left(), wataLink.top(), wataLink.width(), wataLink.height() ) {
@Override
protected void onClick( NoosaInputProcessor.Touch touch ) {
DeviceCompat.openURI("http://" + LNK_WATA);
}
};
add( hotArea );
Archs archs = new Archs();
archs.setSize( Camera.main.width, Camera.main.height );
addToBack( archs );
ExitButton btnExit = new ExitButton();
btnExit.setPos( Camera.main.width - btnExit.width(), 0 );
add( btnExit );
fadeIn();
}
@Override
protected void onBackPressed() {
ShatteredPixelDungeon.switchNoFade(TitleScene.class);
}
}
| 5,279 | AboutScene | java | en | java | code | {"qsc_code_num_words": 623, "qsc_code_num_chars": 5279.0, "qsc_code_mean_word_length": 6.07865169, "qsc_code_frac_words_unique": 0.31300161, "qsc_code_frac_chars_top_2grams": 0.03089517, "qsc_code_frac_chars_top_3grams": 0.09030895, "qsc_code_frac_chars_top_4grams": 0.09294956, "qsc_code_frac_chars_dupe_5grams": 0.23527858, "qsc_code_frac_chars_dupe_6grams": 0.10166359, "qsc_code_frac_chars_dupe_7grams": 0.06390283, "qsc_code_frac_chars_dupe_8grams": 0.04330605, "qsc_code_frac_chars_dupe_9grams": 0.04330605, "qsc_code_frac_chars_dupe_10grams": 0.04330605, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01933019, "qsc_code_frac_chars_whitespace": 0.15722675, "qsc_code_size_file_byte": 5279.0, "qsc_code_num_lines": 163.0, "qsc_code_num_chars_line_max": 114.0, "qsc_code_num_chars_line_mean": 32.38650307, "qsc_code_frac_chars_alphabet": 0.83187233, "qsc_code_frac_chars_comments": 0.15268043, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.09090909, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.03666443, "qsc_code_frac_chars_long_word_length": 0.00514196, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00357702, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05454545, "qsc_codejava_score_lines_no_logic": 0.18181818, "qsc_codejava_frac_words_no_modifier": 0.57142857, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.Rankings;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites;
import com.shatteredpixel.shatteredpixeldungeon.effects.Fireball;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.journal.Journal;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Icons;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.StyledButton;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStartGame;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.utils.FileUtils;
public class WelcomeScene extends PixelScene {
private static int LATEST_UPDATE = ShatteredPixelDungeon.v0_7_5;
@Override
public void create() {
super.create();
final int previousVersion = SPDSettings.version();
if (ShatteredPixelDungeon.versionCode == previousVersion) {
ShatteredPixelDungeon.switchNoFade(TitleScene.class);
return;
}
uiCamera.visible = false;
int w = Camera.main.width;
int h = Camera.main.height;
Image title = BannerSprites.get( BannerSprites.Type.PIXEL_DUNGEON );
title.brightness(0.6f);
add( title );
float topRegion = Math.max(title.height, h*0.45f);
title.x = (w - title.width()) / 2f;
if (SPDSettings.landscape()) {
title.y = (topRegion - title.height()) / 2f;
} else {
title.y = 20 + (topRegion - title.height() - 20) / 2f;
}
align(title);
Image signs = new Image( BannerSprites.get( BannerSprites.Type.PIXEL_DUNGEON_SIGNS ) ) {
private float time = 0;
@Override
public void update() {
super.update();
am = Math.max(0f, (float)Math.sin( time += Game.elapsed ));
if (time >= 1.5f*Math.PI) time = 0;
}
@Override
public void draw() {
Blending.setLightMode();
super.draw();
Blending.setNormalMode();
}
};
signs.x = title.x + (title.width() - signs.width())/2f;
signs.y = title.y;
add( signs );
StyledButton okay = new StyledButton(Chrome.Type.GREY_BUTTON_TR, Messages.get(this, "continue")){
@Override
protected void onClick() {
super.onClick();
if (previousVersion == 0){
SPDSettings.version(ShatteredPixelDungeon.versionCode);
WelcomeScene.this.add(new WndStartGame(1));
} else {
updateVersion(previousVersion);
ShatteredPixelDungeon.switchScene(TitleScene.class);
}
}
};
//FIXME these buttons are very low on 18:9 devices
if (previousVersion != 0){
StyledButton changes = new StyledButton(Chrome.Type.GREY_BUTTON_TR, Messages.get(TitleScene.class, "changes")){
@Override
protected void onClick() {
super.onClick();
updateVersion(previousVersion);
ShatteredPixelDungeon.switchScene(ChangesScene.class);
}
};
okay.setRect(title.x, h-25, (title.width()/2)-2, 21);
add(okay);
changes.setRect(okay.right()+2, h-25, (title.width()/2)-2, 21);
changes.icon(Icons.get(Icons.CHANGES));
add(changes);
} else {
okay.text(Messages.get(TitleScene.class, "enter"));
okay.setRect(title.x, h-25, title.width(), 21);
okay.icon(Icons.get(Icons.ENTER));
add(okay);
}
RenderedTextBlock text = PixelScene.renderTextBlock(6);
String message;
if (previousVersion == 0) {
message = Messages.get(this, "welcome_msg");
} else if (previousVersion <= ShatteredPixelDungeon.versionCode) {
if (previousVersion < LATEST_UPDATE){
message = Messages.get(this, "update_intro");
message += "\n\n" + Messages.get(this, "update_msg");
} else {
//TODO: change the messages here in accordance with the type of patch.
message = Messages.get(this, "patch_intro");
message += "\n";
message += "\n" + Messages.get(this, "patch_balance");
message += "\n" + Messages.get(this, "patch_bugfixes");
message += "\n" + Messages.get(this, "patch_translations");
}
} else {
message = Messages.get(this, "what_msg");
}
text.text(message, w-20);
float textSpace = h - title.y - (title.height() - 10) - okay.height() - 2;
text.setPos((w - text.width()) / 2f, title.y+(title.height() - 10) + ((textSpace - text.height()) / 2));
add(text);
}
private void updateVersion(int previousVersion){
//update rankings, to update any data which may be outdated
if (previousVersion < LATEST_UPDATE){
try {
Rankings.INSTANCE.load();
Rankings.INSTANCE.save();
} catch (Exception e) {
//if we encounter a fatal error, then just clear the rankings
FileUtils.deleteFile( Rankings.RANKINGS_FILE );
}
}
//give classes to people with saves that have previously unlocked them
if (previousVersion <= ShatteredPixelDungeon.v0_7_0c){
Badges.loadGlobal();
Badges.addGlobal(Badges.Badge.UNLOCK_MAGE);
Badges.addGlobal(Badges.Badge.UNLOCK_ROGUE);
if (Badges.isUnlocked(Badges.Badge.BOSS_SLAIN_3)){
Badges.addGlobal(Badges.Badge.UNLOCK_HUNTRESS);
}
Badges.saveGlobal();
}
if (previousVersion <= ShatteredPixelDungeon.v0_6_5c){
Journal.loadGlobal();
Document.ALCHEMY_GUIDE.addPage("Potions");
Document.ALCHEMY_GUIDE.addPage("Stones");
Document.ALCHEMY_GUIDE.addPage("Energy_Food");
Journal.saveGlobal();
}
SPDSettings.version(ShatteredPixelDungeon.versionCode);
}
private void placeTorch( float x, float y ) {
Fireball fb = new Fireball();
fb.setPos( x, y );
add( fb );
}
}
| 6,639 | WelcomeScene | java | en | java | code | {"qsc_code_num_words": 786, "qsc_code_num_chars": 6639.0, "qsc_code_mean_word_length": 5.99491094, "qsc_code_frac_words_unique": 0.34351145, "qsc_code_frac_chars_top_2grams": 0.03629032, "qsc_code_frac_chars_top_3grams": 0.12096774, "qsc_code_frac_chars_top_4grams": 0.13073005, "qsc_code_frac_chars_dupe_5grams": 0.21965195, "qsc_code_frac_chars_dupe_6grams": 0.10335314, "qsc_code_frac_chars_dupe_7grams": 0.03756367, "qsc_code_frac_chars_dupe_8grams": 0.03310696, "qsc_code_frac_chars_dupe_9grams": 0.02037351, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0141704, "qsc_code_frac_chars_whitespace": 0.1602651, "qsc_code_size_file_byte": 6639.0, "qsc_code_num_lines": 202.0, "qsc_code_num_chars_line_max": 115.0, "qsc_code_num_chars_line_mean": 32.86633663, "qsc_code_frac_chars_alphabet": 0.83103139, "qsc_code_frac_chars_comments": 0.16433198, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.17880795, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.02757751, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0049505, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04635762, "qsc_codejava_score_lines_no_logic": 0.19205298, "qsc_codejava_frac_words_no_modifier": 0.875, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/IntroScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.watabou.noosa.Game;
public class IntroScene extends PixelScene {
@Override
public void create() {
super.create();
add( new WndStory( Messages.get(this, "text") ) {
@Override
public void hide() {
super.hide();
Game.switchScene( InterlevelScene.class );
}
} );
fadeIn();
}
}
| 1,289 | IntroScene | java | en | java | code | {"qsc_code_num_words": 172, "qsc_code_num_chars": 1289.0, "qsc_code_mean_word_length": 5.51744186, "qsc_code_frac_words_unique": 0.61627907, "qsc_code_frac_chars_top_2grams": 0.03477345, "qsc_code_frac_chars_top_3grams": 0.04109589, "qsc_code_frac_chars_top_4grams": 0.06006322, "qsc_code_frac_chars_dupe_5grams": 0.08640674, "qsc_code_frac_chars_dupe_6grams": 0.05900948, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01606805, "qsc_code_frac_chars_whitespace": 0.17920869, "qsc_code_size_file_byte": 1289.0, "qsc_code_num_lines": 43.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 29.97674419, "qsc_code_frac_chars_alphabet": 0.88090737, "qsc_code_frac_chars_comments": 0.60589604, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11111111, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00787402, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.11111111, "qsc_codejava_score_lines_no_logic": 0.33333333, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.BitmapText;
import com.watabou.noosa.BitmapText.Font;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
import com.watabou.noosa.Scene;
import com.watabou.noosa.Visual;
import com.watabou.noosa.ui.Component;
import com.watabou.utils.BitmapCache;
import com.watabou.utils.Reflection;
import java.util.ArrayList;
public class PixelScene extends Scene {
// Minimum virtual display size for portrait orientation
public static final float MIN_WIDTH_P = 135;
public static final float MIN_HEIGHT_P = 225;
// Minimum virtual display size for landscape orientation
public static final float MIN_WIDTH_L = 240;
public static final float MIN_HEIGHT_L = 160;
public static int defaultZoom = 0;
public static int maxDefaultZoom = 0;
public static int maxScreenZoom = 0;
public static float minZoom;
public static float maxZoom;
public static Camera uiCamera;
//stylized 3x5 bitmapped pixel font. Only latin characters supported.
public static BitmapText.Font pixelFont;
@Override
public void create() {
super.create();
GameScene.scene = null;
float minWidth, minHeight;
if (SPDSettings.landscape()) {
minWidth = MIN_WIDTH_L;
minHeight = MIN_HEIGHT_L;
} else {
minWidth = MIN_WIDTH_P;
minHeight = MIN_HEIGHT_P;
}
maxDefaultZoom = (int)Math.min(Game.width/minWidth, Game.height/minHeight);
defaultZoom = SPDSettings.scale();
if (defaultZoom < Math.ceil( Game.density * 2 ) || defaultZoom > maxDefaultZoom){
defaultZoom = (int)Math.round((Math.ceil( Game.density * 2 ) + maxDefaultZoom)/2);
while ((
Game.width / defaultZoom < minWidth ||
Game.height / defaultZoom < minHeight
) && defaultZoom > 1) {
defaultZoom--;
}
}
minZoom = 1;
maxZoom = defaultZoom * 2;
Camera.reset( new PixelCamera( defaultZoom ) );
float uiZoom = defaultZoom;
uiCamera = Camera.createFullscreen( uiZoom );
Camera.add( uiCamera );
if (pixelFont == null) {
// 3x5 (6)
pixelFont = Font.colorMarked(
BitmapCache.get( Assets.PIXELFONT), 0x00000000, BitmapText.Font.LATIN_FULL );
pixelFont.baseLine = 6;
pixelFont.tracking = -1;
}
}
//FIXME this system currently only works for a subset of windows
private static ArrayList<Class<?extends Window>> savedWindows = new ArrayList<>();
private static Class<?extends PixelScene> savedClass = null;
public void saveWindows(){
savedWindows.clear();
savedClass = getClass();
for (Gizmo g : members.toArray(new Gizmo[0])){
if (g instanceof Window){
savedWindows.add((Class<? extends Window>) g.getClass());
}
}
}
public void restoreWindows(){
if (getClass().equals(savedClass)){
for (Class<?extends Window> w : savedWindows){
try{
add(Reflection.newInstanceUnhandled(w));
} catch (Exception e){
//window has no public zero-arg constructor, just eat the exception
}
}
}
savedWindows.clear();
}
@Override
public void destroy() {
super.destroy();
Game.instance.getInputProcessor().removeAllTouchEvent();
}
public static RenderedTextBlock renderTextBlock(int size ){
return renderTextBlock("", size);
}
public static RenderedTextBlock renderTextBlock(String text, int size ){
RenderedTextBlock result = new RenderedTextBlock( text, size*defaultZoom);
result.zoom(1/(float)defaultZoom);
return result;
}
/**
* These methods align UI elements to device pixels.
* e.g. if we have a scale of 3x then valid positions are #.0, #.33, #.67
*/
public static float align( float pos ) {
return Math.round(pos * defaultZoom) / (float)defaultZoom;
}
public static float align( Camera camera, float pos ) {
return Math.round(pos * camera.zoom) / camera.zoom;
}
public static void align( Visual v ) {
v.x = align( v.x );
v.y = align( v.y );
}
public static void align( Component c ){
c.setPos(align(c.left()), align(c.top()));
}
public static boolean noFade = false;
protected void fadeIn() {
if (noFade) {
noFade = false;
} else {
fadeIn( 0xFF000000, false );
}
}
protected void fadeIn( int color, boolean light ) {
add( new Fader( color, light ) );
}
public static void showBadge( Badges.Badge badge ) {
BadgeBanner banner = BadgeBanner.show( badge.image );
banner.camera = uiCamera;
banner.x = align( banner.camera, (banner.camera.width - banner.width) / 2 );
banner.y = align( banner.camera, (banner.camera.height - banner.height) / 3 );
Game.scene().add( banner );
}
protected static class Fader extends ColorBlock {
private static float FADE_TIME = 1f;
private boolean light;
private float time;
public Fader( int color, boolean light ) {
super( uiCamera.width, uiCamera.height, color );
this.light = light;
camera = uiCamera;
alpha( 1f );
time = FADE_TIME;
}
@Override
public void update() {
super.update();
if ((time -= Game.elapsed) <= 0) {
alpha( 0f );
parent.remove( this );
} else {
alpha( time / FADE_TIME );
}
}
@Override
public void draw() {
if (light) {
Blending.setLightMode();
super.draw();
Blending.setNormalMode();
} else {
super.draw();
}
}
}
private static class PixelCamera extends Camera {
public PixelCamera( float zoom ) {
super(
(int)(Game.width - Math.ceil( Game.width / zoom ) * zoom) / 2,
(int)(Game.height - Math.ceil( Game.height / zoom ) * zoom) / 2,
(int)Math.ceil( Game.width / zoom ),
(int)Math.ceil( Game.height / zoom ), zoom );
fullScreen = true;
}
@Override
protected void updateMatrix() {
float sx = align( this, scroll.x + shakeX );
float sy = align( this, scroll.y + shakeY );
matrix[0] = +zoom * invW2;
matrix[5] = -zoom * invH2;
matrix[12] = -1 + x * invW2 - sx * matrix[0];
matrix[13] = +1 - y * invH2 - sy * matrix[5];
}
}
}
| 7,394 | PixelScene | java | en | java | code | {"qsc_code_num_words": 894, "qsc_code_num_chars": 7394.0, "qsc_code_mean_word_length": 5.68680089, "qsc_code_frac_words_unique": 0.31767338, "qsc_code_frac_chars_top_2grams": 0.03540519, "qsc_code_frac_chars_top_3grams": 0.03776554, "qsc_code_frac_chars_top_4grams": 0.03717545, "qsc_code_frac_chars_dupe_5grams": 0.16601101, "qsc_code_frac_chars_dupe_6grams": 0.07159717, "qsc_code_frac_chars_dupe_7grams": 0.01612903, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01536903, "qsc_code_frac_chars_whitespace": 0.19921558, "qsc_code_size_file_byte": 7394.0, "qsc_code_num_lines": 272.0, "qsc_code_num_chars_line_max": 86.0, "qsc_code_num_chars_line_mean": 27.18382353, "qsc_code_frac_chars_alphabet": 0.84326972, "qsc_code_frac_chars_comments": 0.16770354, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.06914894, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00324992, "qsc_code_frac_lines_prompt_comments": 0.00367647, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09042553, "qsc_codejava_score_lines_no_logic": 0.2393617, "qsc_codejava_frac_words_no_modifier": 0.88888889, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/SurfaceScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfLivingEarth;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfWarding;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.EarthGuardianSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.GhostSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.RatSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.WardSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.RedButton;
import com.watabou.gltextures.SmartTexture;
import com.watabou.gltextures.TextureCache;
import com.watabou.glwrap.Matrix;
import com.watabou.glwrap.Quad;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.noosa.Camera;
import com.watabou.noosa.ColorBlock;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.TouchArea;
import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Music;
import com.watabou.utils.Point;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
import java.nio.FloatBuffer;
import java.util.Calendar;
public class SurfaceScene extends PixelScene {
private static final int FRAME_WIDTH = 88;
private static final int FRAME_HEIGHT = 125;
private static final int FRAME_MARGIN_TOP = 9;
private static final int FRAME_MARGIN_X = 4;
private static final int BUTTON_HEIGHT = 20;
private static final int SKY_WIDTH = 80;
private static final int SKY_HEIGHT = 112;
private static final int NSTARS = 100;
private static final int NCLOUDS = 5;
private Camera viewport;
@Override
public void create() {
super.create();
Music.INSTANCE.play( Assets.HAPPY, true );
uiCamera.visible = false;
int w = Camera.main.width;
int h = Camera.main.height;
Archs archs = new Archs();
archs.reversed = true;
archs.setSize( w, h );
add( archs );
float vx = align((w - SKY_WIDTH) / 2f);
float vy = align((h - SKY_HEIGHT - BUTTON_HEIGHT) / 2f);
Point s = Camera.main.cameraToScreen( vx, vy );
viewport = new Camera( s.x, s.y, SKY_WIDTH, SKY_HEIGHT, defaultZoom );
Camera.add( viewport );
Group window = new Group();
window.camera = viewport;
add( window );
boolean dayTime = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) >= 7;
Sky sky = new Sky( dayTime );
sky.scale.set( SKY_WIDTH, SKY_HEIGHT );
window.add( sky );
if (!dayTime) {
for (int i=0; i < NSTARS; i++) {
float size = Random.Float();
ColorBlock star = new ColorBlock( size, size, 0xFFFFFFFF );
star.x = Random.Float( SKY_WIDTH ) - size / 2;
star.y = Random.Float( SKY_HEIGHT ) - size / 2;
star.am = size * (1 - star.y / SKY_HEIGHT);
window.add( star );
}
}
float range = SKY_HEIGHT * 2 / 3;
for (int i=0; i < NCLOUDS; i++) {
Cloud cloud = new Cloud( (NCLOUDS - 1 - i) * (range / NCLOUDS) + Random.Float( range / NCLOUDS ), dayTime );
window.add( cloud );
}
int nPatches = (int)(sky.width() / GrassPatch.WIDTH + 1);
for (int i=0; i < nPatches * 4; i++) {
GrassPatch patch = new GrassPatch( (i - 0.75f) * GrassPatch.WIDTH / 4, SKY_HEIGHT + 1, dayTime );
patch.brightness( dayTime ? 0.7f : 0.4f );
window.add( patch );
}
Avatar a = new Avatar( Dungeon.hero.heroClass );
// Removing semitransparent contour
a.am = 2; a.aa = -1;
a.x = (SKY_WIDTH - a.width) / 2;
a.y = SKY_HEIGHT - a.height;
align(a);
final Pet pet = new Pet();
pet.rm = pet.gm = pet.bm = 1.2f;
pet.x = SKY_WIDTH / 2 + 2;
pet.y = SKY_HEIGHT - pet.height;
align(pet);
//allies. Attempts to pick highest level, but prefers rose > earth > ward.
//Rose level is halved because it's easier to upgrade
CharSprite allySprite = null;
//picks the highest between ghost's weapon, armor, and rose level/2
int roseLevel = 0;
DriedRose rose = Dungeon.hero.belongings.getItem(DriedRose.class);
if (rose != null){
roseLevel = rose.level()/2;
if (rose.ghostWeapon() != null){
roseLevel = Math.max(roseLevel, rose.ghostWeapon().level());
}
if (rose.ghostArmor() != null){
roseLevel = Math.max(roseLevel, rose.ghostArmor().level());
}
}
int earthLevel = Dungeon.hero.belongings.getItem(WandOfLivingEarth.class) == null ? 0 : Dungeon.hero.belongings.getItem(WandOfLivingEarth.class).level();
int wardLevel = Dungeon.hero.belongings.getItem(WandOfWarding.class) == null ? 0 : Dungeon.hero.belongings.getItem(WandOfWarding.class).level();
MagesStaff staff = Dungeon.hero.belongings.getItem(MagesStaff.class);
if (staff != null){
if (staff.wandClass() == WandOfLivingEarth.class){
earthLevel = Math.max(earthLevel, staff.level());
} else if (staff.wandClass() == WandOfWarding.class){
wardLevel = Math.max(wardLevel, staff.level());
}
}
if (roseLevel >= 3 && roseLevel >= earthLevel && roseLevel >= wardLevel){
allySprite = new GhostSprite();
if (dayTime) allySprite.alpha(0.4f);
} else if (earthLevel >= 3 && earthLevel >= wardLevel){
allySprite = new EarthGuardianSprite();
} else if (wardLevel >= 3){
allySprite = new WardSprite();
((WardSprite) allySprite).updateTier(Math.min(wardLevel+2, 6));
}
if (allySprite != null){
allySprite.add(CharSprite.State.PARALYSED);
allySprite.scale = new PointF(2, 2);
allySprite.x = a.x - allySprite.width()*0.75f;
allySprite.y = SKY_HEIGHT - allySprite.height();
align(allySprite);
window.add(allySprite);
}
window.add( a );
window.add( pet );
window.add( new TouchArea( sky ) {
protected void onClick( NoosaInputProcessor.Touch touch ) {
pet.jump();
}
} );
for (int i=0; i < nPatches; i++) {
GrassPatch patch = new GrassPatch( (i - 0.5f) * GrassPatch.WIDTH, SKY_HEIGHT, dayTime );
patch.brightness( dayTime ? 1.0f : 0.8f );
window.add( patch );
}
Image frame = new Image( Assets.SURFACE );
frame.frame( 0, 0, FRAME_WIDTH, FRAME_HEIGHT );
frame.x = vx - FRAME_MARGIN_X;
frame.y = vy - FRAME_MARGIN_TOP;
add( frame );
if (dayTime) {
a.brightness( 1.2f );
pet.brightness( 1.2f );
} else {
frame.hardlight( 0xDDEEFF );
}
RedButton gameOver = new RedButton( Messages.get(this, "exit") ) {
protected void onClick() {
Game.switchScene( RankingsScene.class );
}
};
gameOver.setSize( SKY_WIDTH - FRAME_MARGIN_X * 2, BUTTON_HEIGHT );
gameOver.setPos( frame.x + FRAME_MARGIN_X * 2, frame.y + frame.height + 4 );
add( gameOver );
Badges.validateHappyEnd();
fadeIn();
}
@Override
public void destroy() {
Badges.saveGlobal();
Camera.remove( viewport );
super.destroy();
}
@Override
protected void onBackPressed() {
}
private static class Sky extends Visual {
private static final int[] day = {0xFF4488FF, 0xFFCCEEFF};
private static final int[] night = {0xFF001155, 0xFF335980};
private SmartTexture texture;
private FloatBuffer verticesBuffer;
public Sky( boolean dayTime ) {
super( 0, 0, 1, 1 );
texture = TextureCache.createGradient( dayTime ? day : night );
float[] vertices = new float[16];
verticesBuffer = Quad.create();
vertices[2] = 0.25f;
vertices[6] = 0.25f;
vertices[10] = 0.75f;
vertices[14] = 0.75f;
vertices[3] = 0;
vertices[7] = 1;
vertices[11] = 1;
vertices[15] = 0;
vertices[0] = 0;
vertices[1] = 0;
vertices[4] = 1;
vertices[5] = 0;
vertices[8] = 1;
vertices[9] = 1;
vertices[12] = 0;
vertices[13] = 1;
verticesBuffer.position( 0 );
verticesBuffer.put( vertices );
}
@Override
public void draw() {
super.draw();
NoosaScript script = NoosaScript.get();
texture.bind();
script.camera( camera() );
script.uModel.valueM4( matrix );
script.lighting(
rm, gm, bm, am,
ra, ga, ba, aa );
script.drawQuad( verticesBuffer );
}
}
private static class Cloud extends Image {
private static int lastIndex = -1;
public Cloud( float y, boolean dayTime ) {
super( Assets.SURFACE );
int index;
do {
index = Random.Int( 3 );
} while (index == lastIndex);
switch (index) {
case 0:
frame( 88, 0, 49, 20 );
break;
case 1:
frame( 88, 20, 49, 22 );
break;
case 2:
frame( 88, 42, 50, 18 );
break;
}
lastIndex = index;
this.y = y;
scale.set( 1 - y / SKY_HEIGHT );
x = Random.Float( SKY_WIDTH + width() ) - width();
speed.x = scale.x * (dayTime ? +8 : -8);
if (dayTime) {
tint( 0xCCEEFF, 1 - scale.y );
} else {
rm = gm = bm = +3.0f;
ra = ga = ba = -2.1f;
}
}
@Override
public void update() {
super.update();
if (speed.x > 0 && x > SKY_WIDTH) {
x = -width();
} else if (speed.x < 0 && x < -width()) {
x = SKY_WIDTH;
}
}
}
private static class Avatar extends Image {
private static final int WIDTH = 24;
private static final int HEIGHT = 32;
public Avatar( HeroClass cl ) {
super( Assets.AVATARS );
frame( new TextureFilm( texture, WIDTH, HEIGHT ).get( cl.ordinal() ) );
}
}
private static class Pet extends RatSprite {
public void jump() {
play( run );
}
@Override
public void onComplete( Animation anim ) {
if (anim == run) {
idle();
}
}
}
private static class GrassPatch extends Image {
public static final int WIDTH = 16;
public static final int HEIGHT = 14;
private float tx;
private float ty;
private double a = Random.Float( 5 );
private double angle;
private boolean forward;
public GrassPatch( float tx, float ty, boolean forward ) {
super( Assets.SURFACE );
frame( 88 + Random.Int( 4 ) * WIDTH, 60, WIDTH, HEIGHT );
this.tx = tx;
this.ty = ty;
this.forward = forward;
}
@Override
public void update() {
super.update();
a += Random.Float( Game.elapsed * 5 );
angle = (2 + Math.cos( a )) * (forward ? +0.2 : -0.2);
scale.y = (float)Math.cos( angle );
x = tx + (float)Math.tan( angle ) * width;
y = ty - scale.y * height;
}
@Override
protected void updateMatrix() {
super.updateMatrix();
Matrix.skewX( matrix, (float)(angle / Matrix.G2RAD) );
}
}
}
| 11,766 | SurfaceScene | java | en | java | code | {"qsc_code_num_words": 1481, "qsc_code_num_chars": 11766.0, "qsc_code_mean_word_length": 5.24240378, "qsc_code_frac_words_unique": 0.24105334, "qsc_code_frac_chars_top_2grams": 0.03941267, "qsc_code_frac_chars_top_3grams": 0.03709428, "qsc_code_frac_chars_top_4grams": 0.09067491, "qsc_code_frac_chars_dupe_5grams": 0.16885626, "qsc_code_frac_chars_dupe_6grams": 0.08526533, "qsc_code_frac_chars_dupe_7grams": 0.01777434, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02516941, "qsc_code_frac_chars_whitespace": 0.20984192, "qsc_code_size_file_byte": 11766.0, "qsc_code_num_lines": 435.0, "qsc_code_num_chars_line_max": 156.0, "qsc_code_num_chars_line_mean": 27.04827586, "qsc_code_frac_chars_alphabet": 0.80993869, "qsc_code_frac_chars_comments": 0.08584056, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.07255521, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00037189, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00613611, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03470032, "qsc_codejava_score_lines_no_logic": 0.17665615, "qsc_codejava_frac_words_no_modifier": 0.91666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.badlogic.gdx.utils.IntMap;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.BannerSprites;
import com.shatteredpixel.shatteredpixeldungeon.effects.BlobEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.CircleArc;
import com.shatteredpixel.shatteredpixeldungeon.effects.EmoIcon;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.effects.FloatingText;
import com.shatteredpixel.shatteredpixeldungeon.effects.Ripple;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.Honeypot;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.DriedRose;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.MagicalHolster;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.PotionBandolier;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.ScrollHolder;
import com.shatteredpixel.shatteredpixeldungeon.items.bags.VelvetPouch;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
import com.shatteredpixel.shatteredpixeldungeon.journal.Journal;
import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.Trap;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.DiscardedItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite;
import com.shatteredpixel.shatteredpixeldungeon.tiles.CustomTilemap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTerrainTilemap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTileSheet;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonWallsTilemap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.FogOfWar;
import com.shatteredpixel.shatteredpixeldungeon.tiles.GridTileMap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.RaisedTerrainTilemap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.TerrainFeaturesTilemap;
import com.shatteredpixel.shatteredpixeldungeon.tiles.WallBlockingTilemap;
import com.shatteredpixel.shatteredpixeldungeon.ui.ActionIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.Banner;
import com.shatteredpixel.shatteredpixeldungeon.ui.BusyIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.CharHealthIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.GameLog;
import com.shatteredpixel.shatteredpixeldungeon.ui.LootIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toast;
import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag.Mode;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndGame;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndHero;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoCell;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoMob;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoPlant;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoTrap;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndStory;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem;
import com.watabou.input.NoosaInputProcessor;
import com.watabou.glwrap.Blending;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Gizmo;
import com.watabou.noosa.Group;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.NoosaScriptNoLighting;
import com.watabou.noosa.SkinnedBlock;
import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.utils.GameMath;
import com.watabou.utils.Random;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
public class GameScene extends PixelScene {
static GameScene scene;
private SkinnedBlock water;
private DungeonTerrainTilemap tiles;
private GridTileMap visualGrid;
private TerrainFeaturesTilemap terrainFeatures;
private RaisedTerrainTilemap raisedTerrain;
private DungeonWallsTilemap walls;
private WallBlockingTilemap wallBlocking;
private FogOfWar fog;
private HeroSprite hero;
private StatusPane pane;
private GameLog log;
private BusyIndicator busy;
private CircleArc counter;
private static CellSelector cellSelector;
private Group terrain;
private Group customTiles;
private Group levelVisuals;
private Group customWalls;
private Group ripples;
private Group plants;
private Group traps;
private Group heaps;
private Group mobs;
private Group emitters;
private Group effects;
private Group gases;
private Group spells;
private Group statuses;
private Group emoicons;
private Group healthIndicators;
private Toolbar toolbar;
private Toast prompt;
private AttackIndicator attack;
private LootIndicator loot;
private ActionIndicator action;
private ResumeIndicator resume;
@Override
public void create() {
if (Dungeon.hero == null){
ShatteredPixelDungeon.switchNoFade(TitleScene.class);
return;
}
Music.INSTANCE.play( Assets.TUNE, true );
SPDSettings.lastClass(Dungeon.hero.heroClass.ordinal());
super.create();
Camera.main.zoom( GameMath.gate(minZoom, defaultZoom + SPDSettings.zoom(), maxZoom));
scene = this;
terrain = new Group();
add( terrain );
water = new SkinnedBlock(
Dungeon.level.width() * DungeonTilemap.SIZE,
Dungeon.level.height() * DungeonTilemap.SIZE,
Dungeon.level.waterTex() ){
@Override
protected NoosaScript script() {
return NoosaScriptNoLighting.get();
}
@Override
public void draw() {
//water has no alpha component, this improves performance
Blending.disable();
super.draw();
Blending.enable();
}
};
terrain.add( water );
ripples = new Group();
terrain.add( ripples );
DungeonTileSheet.setupVariance(Dungeon.level.map.length, Dungeon.seedCurDepth());
tiles = new DungeonTerrainTilemap();
terrain.add( tiles );
customTiles = new Group();
terrain.add(customTiles);
for( CustomTilemap visual : Dungeon.level.customTiles){
addCustomTile(visual);
}
visualGrid = new GridTileMap();
terrain.add( visualGrid );
terrainFeatures = new TerrainFeaturesTilemap(Dungeon.level.plants, Dungeon.level.traps);
terrain.add(terrainFeatures);
levelVisuals = Dungeon.level.addVisuals();
add(levelVisuals);
heaps = new Group();
add( heaps );
for ( Heap heap : Dungeon.level.heaps.valueList() ) {
addHeapSprite( heap );
}
emitters = new Group();
effects = new Group();
healthIndicators = new Group();
emoicons = new Group();
mobs = new Group();
add( mobs );
for (Mob mob : Dungeon.level.mobs) {
addMobSprite( mob );
if (Statistics.amuletObtained) {
mob.beckon( Dungeon.hero.pos );
}
}
raisedTerrain = new RaisedTerrainTilemap();
add( raisedTerrain );
walls = new DungeonWallsTilemap();
add(walls);
customWalls = new Group();
add(customWalls);
for( CustomTilemap visual : Dungeon.level.customWalls){
addCustomWall(visual);
}
wallBlocking = new WallBlockingTilemap();
add (wallBlocking);
add( emitters );
add( effects );
gases = new Group();
add( gases );
for (Blob blob : Dungeon.level.blobs.values()) {
blob.emitter = null;
addBlobSprite( blob );
}
fog = new FogOfWar( Dungeon.level.width(), Dungeon.level.height() );
add( fog );
spells = new Group();
add( spells );
statuses = new Group();
add( statuses );
add( healthIndicators );
//always appears ontop of other health indicators
add( new TargetHealthIndicator() );
add( emoicons );
hero = new HeroSprite();
hero.place( Dungeon.hero.pos );
hero.updateArmor();
mobs.add( hero );
add( cellSelector = new CellSelector( tiles ) );
pane = new StatusPane();
pane.camera = uiCamera;
pane.setSize( uiCamera.width, 0 );
add( pane );
toolbar = new Toolbar();
toolbar.camera = uiCamera;
toolbar.setRect( 0,uiCamera.height - toolbar.height(), uiCamera.width, toolbar.height() );
add( toolbar );
attack = new AttackIndicator();
attack.camera = uiCamera;
add( attack );
loot = new LootIndicator();
loot.camera = uiCamera;
add( loot );
action = new ActionIndicator();
action.camera = uiCamera;
add( action );
resume = new ResumeIndicator();
resume.camera = uiCamera;
add( resume );
log = new GameLog();
log.camera = uiCamera;
log.newLine();
add( log );
layoutTags();
busy = new BusyIndicator();
busy.camera = uiCamera;
busy.x = 1;
busy.y = pane.bottom() + 1;
add( busy );
counter = new CircleArc(18, 4.25f);
counter.color( 0x808080, true );
counter.camera = uiCamera;
counter.show(this, busy.center(), 0f);
switch (InterlevelScene.mode) {
case RESURRECT:
ScrollOfTeleportation.appear( Dungeon.hero, Dungeon.level.entrance );
new Flare( 8, 32 ).color( 0xFFFF66, true ).show( hero, 2f ) ;
break;
case RETURN:
ScrollOfTeleportation.appear( Dungeon.hero, Dungeon.hero.pos );
break;
case DESCEND:
switch (Dungeon.depth) {
case 1:
WndStory.showChapter( WndStory.ID_SEWERS );
break;
case 6:
WndStory.showChapter( WndStory.ID_PRISON );
break;
case 11:
WndStory.showChapter( WndStory.ID_CAVES );
break;
case 16:
WndStory.showChapter( WndStory.ID_CITY );
break;
case 22:
WndStory.showChapter( WndStory.ID_HALLS );
break;
}
if (Dungeon.hero.isAlive() && Dungeon.depth != 22) {
Badges.validateNoKilling();
}
break;
default:
}
ArrayList<Item> dropped = Dungeon.droppedItems.get( Dungeon.depth );
if (dropped != null) {
for (Item item : dropped) {
int pos = Dungeon.level.randomRespawnCell();
if (item instanceof Potion) {
((Potion)item).shatter( pos );
} else if (item instanceof Plant.Seed) {
Dungeon.level.plant( (Plant.Seed)item, pos );
} else if (item instanceof Honeypot) {
Dungeon.level.drop(((Honeypot) item).shatter(null, pos), pos);
} else {
Dungeon.level.drop( item, pos );
}
}
Dungeon.droppedItems.remove( Dungeon.depth );
}
ArrayList<Item> ported = Dungeon.portedItems.get( Dungeon.depth );
if (ported != null){
//TODO currently items are only ported to boss rooms, so this works well
//might want to have a 'near entrance' function if items can be ported elsewhere
int pos;
//try to find a tile with no heap, otherwise just stick items onto a heap.
int tries = 100;
do {
pos = Dungeon.level.randomRespawnCell();
tries--;
} while (tries > 0 && Dungeon.level.heaps.get(pos) != null);
for (Item item : ported) {
Dungeon.level.drop( item, pos ).type = Heap.Type.CHEST;
}
Dungeon.level.heaps.get(pos).type = Heap.Type.CHEST;
Dungeon.level.heaps.get(pos).sprite.link(); //sprite reset to show chest
Dungeon.portedItems.remove( Dungeon.depth );
}
Dungeon.hero.next();
switch (InterlevelScene.mode){
case FALL: case DESCEND: case CONTINUE:
Camera.main.snapTo(hero.center().x, hero.center().y - DungeonTilemap.SIZE * (defaultZoom/Camera.main.zoom));
break;
case ASCEND:
Camera.main.snapTo(hero.center().x, hero.center().y + DungeonTilemap.SIZE * (defaultZoom/Camera.main.zoom));
break;
default:
Camera.main.snapTo(hero.center().x, hero.center().y);
}
Camera.main.panTo(hero.center(), 2.5f);
if (InterlevelScene.mode != InterlevelScene.Mode.NONE) {
if (Dungeon.depth == Statistics.deepestFloor
&& (InterlevelScene.mode == InterlevelScene.Mode.DESCEND || InterlevelScene.mode == InterlevelScene.Mode.FALL)) {
GLog.h(Messages.get(this, "descend"), Dungeon.depth);
Sample.INSTANCE.play(Assets.SND_DESCEND);
for (Char ch : Actor.chars()){
if (ch instanceof DriedRose.GhostHero){
((DriedRose.GhostHero) ch).sayAppeared();
}
}
} else if (InterlevelScene.mode == InterlevelScene.Mode.RESET) {
GLog.h(Messages.get(this, "warp"));
} else {
GLog.h(Messages.get(this, "return"), Dungeon.depth);
}
switch (Dungeon.level.feeling) {
case CHASM:
GLog.w(Messages.get(this, "chasm"));
break;
case WATER:
GLog.w(Messages.get(this, "water"));
break;
case GRASS:
GLog.w(Messages.get(this, "grass"));
break;
case DARK:
GLog.w(Messages.get(this, "dark"));
break;
default:
}
if (Dungeon.level instanceof RegularLevel &&
((RegularLevel) Dungeon.level).secretDoors > Random.IntRange(3, 4)) {
GLog.w(Messages.get(this, "secrets"));
}
InterlevelScene.mode = InterlevelScene.Mode.NONE;
}
fadeIn();
selectCell( defaultCellListener );
}
public void destroy() {
//tell the actor thread to finish, then wait for it to complete any actions it may be doing.
if (actorThread.isAlive()){
synchronized (GameScene.class){
synchronized (actorThread) {
actorThread.interrupt();
}
try {
GameScene.class.wait(5000);
} catch (InterruptedException e) {
ShatteredPixelDungeon.reportException(e);
}
synchronized (actorThread) {
if (Actor.processing()) {
Throwable t = new Throwable();
t.setStackTrace(actorThread.getStackTrace());
throw new RuntimeException("timeout waiting for actor thread! ", t);
}
}
}
}
freezeEmitters = false;
scene = null;
Badges.saveGlobal();
Journal.saveGlobal();
super.destroy();
}
@Override
public synchronized void onPause() {
try {
Dungeon.saveAll();
Badges.saveGlobal();
Journal.saveGlobal();
} catch (IOException e) {
ShatteredPixelDungeon.reportException(e);
}
}
private static final Thread actorThread = new Thread() {
@Override
public void run() {
Actor.process();
}
};
//sometimes UI changes can be prompted by the actor thread.
// We queue any removed element destruction, rather than destroying them in the actor thread.
private ArrayList<Gizmo> toDestroy = new ArrayList<>();
@Override
public synchronized void update() {
if (Dungeon.hero == null || scene == null) {
return;
}
super.update();
if (!freezeEmitters) water.offset( 0, -5 * Game.elapsed );
if (!Actor.processing() && Dungeon.hero.isAlive()) {
if (!actorThread.isAlive()) {
//if cpu cores are limited, game should prefer drawing the current frame
if (Runtime.getRuntime().availableProcessors() == 1) {
actorThread.setPriority(Thread.NORM_PRIORITY - 1);
}
actorThread.setName("SHPD Actor Thread");
Thread.currentThread().setName("SHPD Render Thread");
actorThread.start();
} else {
synchronized (actorThread) {
actorThread.notify();
}
}
}
counter.setSweep((1f - Actor.now()%1f)%1f);
if (Dungeon.hero.ready && Dungeon.hero.paralysed == 0) {
log.newLine();
}
if (tagAttack != attack.active ||
tagLoot != loot.visible ||
tagAction != action.visible ||
tagResume != resume.visible) {
//we only want to change the layout when new tags pop in, not when existing ones leave.
boolean tagAppearing = (attack.active && !tagAttack) ||
(loot.visible && !tagLoot) ||
(action.visible && !tagAction) ||
(resume.visible && !tagResume);
tagAttack = attack.active;
tagLoot = loot.visible;
tagAction = action.visible;
tagResume = resume.visible;
if (tagAppearing) layoutTags();
}
cellSelector.enable(Dungeon.hero.ready);
for (Gizmo g : toDestroy){
g.destroy();
}
toDestroy.clear();
}
private boolean tagAttack = false;
private boolean tagLoot = false;
private boolean tagAction = false;
private boolean tagResume = false;
public static void layoutTags() {
if (scene == null) return;
float tagLeft = SPDSettings.flipTags() ? 0 : uiCamera.width - scene.attack.width();
if (SPDSettings.flipTags()) {
scene.log.setRect(scene.attack.width(), scene.toolbar.top()-2, uiCamera.width - scene.attack.width(), 0);
} else {
scene.log.setRect(0, scene.toolbar.top()-2, uiCamera.width - scene.attack.width(), 0 );
}
float pos = scene.toolbar.top();
if (scene.tagAttack){
scene.attack.setPos( tagLeft, pos - scene.attack.height());
scene.attack.flip(tagLeft == 0);
pos = scene.attack.top();
}
if (scene.tagLoot) {
scene.loot.setPos( tagLeft, pos - scene.loot.height() );
scene.loot.flip(tagLeft == 0);
pos = scene.loot.top();
}
if (scene.tagAction) {
scene.action.setPos( tagLeft, pos - scene.action.height() );
scene.action.flip(tagLeft == 0);
pos = scene.action.top();
}
if (scene.tagResume) {
scene.resume.setPos( tagLeft, pos - scene.resume.height() );
scene.resume.flip(tagLeft == 0);
}
}
@Override
protected void onBackPressed() {
if (!cancel()) {
add( new WndGame() );
}
}
@Override
protected void onMenuPressed() {
if (Dungeon.hero.ready) {
selectItem( null, WndBag.Mode.ALL, null );
}
}
public void addCustomTile( CustomTilemap visual){
customTiles.add( visual.create() );
}
public void addCustomWall( CustomTilemap visual){
customWalls.add( visual.create() );
}
private void addHeapSprite( Heap heap ) {
ItemSprite sprite = heap.sprite = (ItemSprite)heaps.recycle( ItemSprite.class );
sprite.revive();
sprite.link( heap );
heaps.add( sprite );
}
private void addDiscardedSprite( Heap heap ) {
heap.sprite = (DiscardedItemSprite)heaps.recycle( DiscardedItemSprite.class );
heap.sprite.revive();
heap.sprite.link( heap );
heaps.add( heap.sprite );
}
private void addPlantSprite( Plant plant ) {
}
private void addTrapSprite( Trap trap ) {
}
private void addBlobSprite( final Blob gas ) {
if (gas.emitter == null) {
gases.add( new BlobEmitter( gas ) );
}
}
private void addMobSprite( Mob mob ) {
CharSprite sprite = mob.sprite();
sprite.visible = Dungeon.level.heroFOV[mob.pos];
mobs.add( sprite );
sprite.link( mob );
}
private synchronized void prompt( String text ) {
if (prompt != null) {
prompt.killAndErase();
toDestroy.add(prompt);
prompt = null;
}
if (text != null) {
prompt = new Toast( text ) {
@Override
protected void onClose() {
cancel();
}
};
prompt.camera = uiCamera;
prompt.setPos( (uiCamera.width - prompt.width()) / 2, uiCamera.height - 60 );
add( prompt );
}
}
private void showBanner( Banner banner ) {
banner.camera = uiCamera;
banner.x = align( uiCamera, (uiCamera.width - banner.width) / 2 );
banner.y = align( uiCamera, (uiCamera.height - banner.height) / 3 );
addToFront( banner );
}
// -------------------------------------------------------
public static void add( Plant plant ) {
if (scene != null) {
scene.addPlantSprite( plant );
}
}
public static void add( Trap trap ) {
if (scene != null) {
scene.addTrapSprite( trap );
}
}
public static void add( Blob gas ) {
Actor.add( gas );
if (scene != null) {
scene.addBlobSprite( gas );
}
}
public static void add( Heap heap ) {
if (scene != null) {
scene.addHeapSprite( heap );
}
}
public static void discard( Heap heap ) {
if (scene != null) {
scene.addDiscardedSprite( heap );
}
}
public static void add( Mob mob ) {
Dungeon.level.mobs.add( mob );
Actor.add( mob );
scene.addMobSprite( mob );
}
public static void add( Mob mob, float delay ) {
Dungeon.level.mobs.add( mob );
Actor.addDelayed( mob, delay );
scene.addMobSprite( mob );
}
public static void add( EmoIcon icon ) {
scene.emoicons.add( icon );
}
public static void add( CharHealthIndicator indicator ){
if (scene != null) scene.healthIndicators.add(indicator);
}
public static void add( CustomTilemap t, boolean wall ){
if (scene == null) return;
if (wall){
scene.addCustomWall(t);
} else {
scene.addCustomTile(t);
}
}
public static void effect( Visual effect ) {
scene.effects.add( effect );
}
public static Ripple ripple( int pos ) {
if (scene != null) {
Ripple ripple = (Ripple) scene.ripples.recycle(Ripple.class);
ripple.reset(pos);
return ripple;
} else {
return null;
}
}
public static SpellSprite spellSprite() {
return (SpellSprite)scene.spells.recycle( SpellSprite.class );
}
public static Emitter emitter() {
if (scene != null) {
Emitter emitter = (Emitter)scene.emitters.recycle( Emitter.class );
emitter.revive();
return emitter;
} else {
return null;
}
}
public static FloatingText status() {
return scene != null ? (FloatingText)scene.statuses.recycle( FloatingText.class ) : null;
}
public static void pickUp( Item item, int pos ) {
if (scene != null) scene.toolbar.pickup( item, pos );
}
public static void pickUpJournal( Item item, int pos ) {
if (scene != null) scene.pane.pickup( item, pos );
}
public static void flashJournal(){
if (scene != null) scene.pane.flash();
}
public static void updateKeyDisplay(){
if (scene != null) scene.pane.updateKeys();
}
public static void resetMap() {
if (scene != null) {
scene.tiles.map(Dungeon.level.map, Dungeon.level.width() );
scene.visualGrid.map(Dungeon.level.map, Dungeon.level.width() );
scene.terrainFeatures.map(Dungeon.level.map, Dungeon.level.width() );
scene.raisedTerrain.map(Dungeon.level.map, Dungeon.level.width() );
scene.walls.map(Dungeon.level.map, Dungeon.level.width() );
}
updateFog();
}
//updates the whole map
public static void updateMap() {
if (scene != null) {
scene.tiles.updateMap();
scene.visualGrid.updateMap();
scene.terrainFeatures.updateMap();
scene.raisedTerrain.updateMap();
scene.walls.updateMap();
updateFog();
}
}
public static void updateMap( int cell ) {
if (scene != null) {
scene.tiles.updateMapCell( cell );
scene.visualGrid.updateMapCell( cell );
scene.terrainFeatures.updateMapCell( cell );
scene.raisedTerrain.updateMapCell( cell );
scene.walls.updateMapCell( cell );
//update adjacent cells too
updateFog( cell, 1 );
}
}
public static void plantSeed( int cell ) {
if (scene != null) {
scene.terrainFeatures.growPlant( cell );
}
}
//todo this doesn't account for walls right now
public static void discoverTile( int pos, int oldValue ) {
if (scene != null) {
scene.tiles.discover( pos, oldValue );
}
}
public static void show( Window wnd ) {
if (scene != null) {
cancelCellSelector();
scene.addToFront(wnd);
}
}
public static void updateFog(){
if (scene != null) {
scene.fog.updateFog();
scene.wallBlocking.updateMap();
}
}
public static void updateFog(int x, int y, int w, int h){
if (scene != null) {
scene.fog.updateFogArea(x, y, w, h);
scene.wallBlocking.updateArea(x, y, w, h);
}
}
public static void updateFog( int cell, int radius ){
if (scene != null) {
scene.fog.updateFog( cell, radius );
scene.wallBlocking.updateArea( cell, radius );
}
}
public static void afterObserve() {
if (scene != null) {
for (Mob mob : Dungeon.level.mobs) {
if (mob.sprite != null)
mob.sprite.visible = Dungeon.level.heroFOV[mob.pos];
}
}
}
public static void flash( int color ) {
scene.fadeIn( 0xFF000000 | color, true );
}
public static void gameOver() {
Banner gameOver = new Banner( BannerSprites.get( BannerSprites.Type.GAME_OVER ) );
gameOver.show( 0x000000, 1f );
scene.showBanner( gameOver );
Sample.INSTANCE.play( Assets.SND_DEATH );
}
public static void bossSlain() {
if (Dungeon.hero.isAlive()) {
Banner bossSlain = new Banner( BannerSprites.get( BannerSprites.Type.BOSS_SLAIN ) );
bossSlain.show( 0xFFFFFF, 0.3f, 5f );
scene.showBanner( bossSlain );
Sample.INSTANCE.play( Assets.SND_BOSS );
}
}
public static void handleCell( int cell ) {
cellSelector.select( cell );
}
public static void selectCell( CellSelector.Listener listener ) {
cellSelector.listener = listener;
if (scene != null)
scene.prompt( listener.prompt() );
}
private static boolean cancelCellSelector() {
cellSelector.resetKeyHold();
if (cellSelector.listener != null && cellSelector.listener != defaultCellListener) {
cellSelector.cancel();
return true;
} else {
return false;
}
}
public static WndBag selectItem( WndBag.Listener listener, WndBag.Mode mode, String title ) {
cancelCellSelector();
WndBag wnd =
mode == Mode.SEED ?
WndBag.getBag( VelvetPouch.class, listener, mode, title ) :
mode == Mode.SCROLL ?
WndBag.getBag( ScrollHolder.class, listener, mode, title ) :
mode == Mode.POTION ?
WndBag.getBag( PotionBandolier.class, listener, mode, title ) :
mode == Mode.WAND ?
WndBag.getBag( MagicalHolster.class, listener, mode, title ) :
WndBag.lastBag( listener, mode, title );
if (scene != null) scene.addToFront( wnd );
return wnd;
}
static boolean cancel() {
if (Dungeon.hero != null && (Dungeon.hero.curAction != null || Dungeon.hero.resting)) {
Dungeon.hero.curAction = null;
Dungeon.hero.resting = false;
return true;
} else {
return cancelCellSelector();
}
}
public static void ready() {
selectCell( defaultCellListener );
QuickSlotButton.cancel();
if (scene != null && scene.toolbar != null) scene.toolbar.examining = false;
}
public static void checkKeyHold(){
cellSelector.processKeyHold();
}
public static void examineCell( Integer cell ) {
if (cell == null
|| cell < 0
|| cell > Dungeon.level.length()
|| (!Dungeon.level.visited[cell] && !Dungeon.level.mapped[cell])) {
return;
}
ArrayList<String> names = new ArrayList<>();
final ArrayList<Object> objects = new ArrayList<>();
if (cell == Dungeon.hero.pos) {
objects.add(Dungeon.hero);
names.add(Dungeon.hero.className().toUpperCase(Locale.ENGLISH));
} else {
if (Dungeon.level.heroFOV[cell]) {
Mob mob = (Mob) Actor.findChar(cell);
if (mob != null) {
objects.add(mob);
names.add(Messages.titleCase( mob.name ));
}
}
}
Heap heap = Dungeon.level.heaps.get(cell);
if (heap != null && heap.seen) {
objects.add(heap);
names.add(Messages.titleCase( heap.toString() ));
}
Plant plant = Dungeon.level.plants.get( cell );
if (plant != null) {
objects.add(plant);
names.add(Messages.titleCase( plant.plantName ));
}
Trap trap = Dungeon.level.traps.get( cell );
if (trap != null && trap.visible) {
objects.add(trap);
names.add(Messages.titleCase( trap.name ));
}
if (objects.isEmpty()) {
GameScene.show(new WndInfoCell(cell));
} else if (objects.size() == 1){
examineObject(objects.get(0));
} else {
GameScene.show(new WndOptions(Messages.get(GameScene.class, "choose_examine"),
Messages.get(GameScene.class, "multiple_examine"), names.toArray(new String[names.size()])){
@Override
protected void onSelect(int index) {
examineObject(objects.get(index));
}
});
}
}
public static void examineObject(Object o){
if (o == Dungeon.hero){
GameScene.show( new WndHero() );
} else if ( o instanceof Mob ){
GameScene.show(new WndInfoMob((Mob) o));
} else if ( o instanceof Heap ){
Heap heap = (Heap)o;
if (heap.type == Heap.Type.FOR_SALE && heap.size() == 1 && heap.peek().price() > 0) {
GameScene.show(new WndTradeItem(heap, false));
} else {
GameScene.show(new WndInfoItem(heap));
}
} else if ( o instanceof Plant ){
GameScene.show( new WndInfoPlant((Plant) o) );
} else if ( o instanceof Trap ){
GameScene.show( new WndInfoTrap((Trap) o));
} else {
GameScene.show( new WndMessage( Messages.get(GameScene.class, "dont_know") ) ) ;
}
}
private static final CellSelector.Listener defaultCellListener = new CellSelector.Listener() {
@Override
public void onSelect( Integer cell ) {
if (NoosaInputProcessor.modifier) {
examineCell( cell );
} else {
if (Dungeon.hero.handle(cell)) {
Dungeon.hero.next();
}
}
}
@Override
public String prompt() {
return null;
}
};
}
| 30,794 | GameScene | java | en | java | code | {"qsc_code_num_words": 3401, "qsc_code_num_chars": 30794.0, "qsc_code_mean_word_length": 6.36489268, "qsc_code_frac_words_unique": 0.18612173, "qsc_code_frac_chars_top_2grams": 0.03783434, "qsc_code_frac_chars_top_3grams": 0.13341341, "qsc_code_frac_chars_top_4grams": 0.15244607, "qsc_code_frac_chars_dupe_5grams": 0.2801312, "qsc_code_frac_chars_dupe_6grams": 0.0897584, "qsc_code_frac_chars_dupe_7grams": 0.04822839, "qsc_code_frac_chars_dupe_8grams": 0.03561694, "qsc_code_frac_chars_dupe_9grams": 0.02545387, "qsc_code_frac_chars_dupe_10grams": 0.02369843, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00435226, "qsc_code_frac_chars_whitespace": 0.17178671, "qsc_code_size_file_byte": 30794.0, "qsc_code_num_lines": 1095.0, "qsc_code_num_chars_line_max": 119.0, "qsc_code_num_chars_line_mean": 28.12237443, "qsc_code_frac_chars_alphabet": 0.84441656, "qsc_code_frac_chars_comments": 0.05517309, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11704545, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0051899, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00144355, "qsc_code_frac_lines_prompt_comments": 0.00091324, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07272727, "qsc_codejava_score_lines_no_logic": 0.2375, "qsc_codejava_frac_words_no_modifier": 0.93846154, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/scenes/BadgesScene.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.scenes;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.SPDSettings;
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon;
import com.shatteredpixel.shatteredpixeldungeon.effects.BadgeBanner;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.ui.Archs;
import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.RenderedTextBlock;
import com.shatteredpixel.shatteredpixeldungeon.ui.Window;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBadge;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.Image;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.ui.Button;
import com.watabou.utils.Random;
import java.util.List;
public class BadgesScene extends PixelScene {
@Override
public void create() {
super.create();
Music.INSTANCE.play( Assets.THEME, true );
uiCamera.visible = false;
int w = Camera.main.width;
int h = Camera.main.height;
Archs archs = new Archs();
archs.setSize( w, h );
add( archs );
float left = 5;
float top = 20;
RenderedTextBlock title = PixelScene.renderTextBlock( Messages.get(this, "title"), 9 );
title.hardlight(Window.TITLE_COLOR);
title.setPos(
(w - title.width()) / 2f,
(top - title.height()) / 2f
);
align(title);
add(title);
Badges.loadGlobal();
List<Badges.Badge> badges = Badges.filtered( true );
int blankBadges = 36;
blankBadges -= badges.size();
if (badges.contains(Badges.Badge.ALL_ITEMS_IDENTIFIED)) blankBadges -= 6;
if (badges.contains(Badges.Badge.YASD)) blankBadges -= 5;
blankBadges = Math.max(0, blankBadges);
//guarantees a max of 5 rows in landscape, and 8 in portrait, assuming a max of 40 buttons
int nCols = SPDSettings.landscape() ? 7 : 4;
if (badges.size() + blankBadges > 32 && !SPDSettings.landscape()) nCols++;
int nRows = 1 + (blankBadges + badges.size())/nCols;
float badgeWidth = (w - 2*left)/nCols;
float badgeHeight = (h - 2*top)/nRows;
for (int i = 0; i < badges.size() + blankBadges; i++){
int row = i / nCols;
int col = i % nCols;
Badges.Badge b = i < badges.size() ? badges.get( i ) : null;
BadgeButton button = new BadgeButton( b );
button.setPos(
left + col * badgeWidth + (badgeWidth - button.width()) / 2,
top + row * badgeHeight + (badgeHeight - button.height()) / 2);
align(button);
add( button );
}
ExitButton btnExit = new ExitButton();
btnExit.setPos( Camera.main.width - btnExit.width(), 0 );
add( btnExit );
fadeIn();
}
@Override
public void destroy() {
Badges.saveGlobal();
super.destroy();
}
@Override
protected void onBackPressed() {
ShatteredPixelDungeon.switchNoFade( TitleScene.class );
}
private static class BadgeButton extends Button {
private Badges.Badge badge;
private Image icon;
public BadgeButton( Badges.Badge badge ) {
super();
this.badge = badge;
active = (badge != null);
icon = active ? BadgeBanner.image(badge.image) : new Image( Assets.LOCKED );
add(icon);
setSize( icon.width(), icon.height() );
}
@Override
protected void layout() {
super.layout();
icon.x = x + (width - icon.width()) / 2;
icon.y = y + (height - icon.height()) / 2;
}
@Override
public void update() {
super.update();
if (Random.Float() < Game.elapsed * 0.1) {
BadgeBanner.highlight( icon, badge.image );
}
}
@Override
protected void onClick() {
Sample.INSTANCE.play( Assets.SND_CLICK, 0.7f, 0.7f, 1.2f );
Game.scene().add( new WndBadge( badge ) );
}
}
}
| 4,638 | BadgesScene | java | en | java | code | {"qsc_code_num_words": 578, "qsc_code_num_chars": 4638.0, "qsc_code_mean_word_length": 5.66262976, "qsc_code_frac_words_unique": 0.3650519, "qsc_code_frac_chars_top_2grams": 0.04949588, "qsc_code_frac_chars_top_3grams": 0.13932172, "qsc_code_frac_chars_top_4grams": 0.14787657, "qsc_code_frac_chars_dupe_5grams": 0.1136572, "qsc_code_frac_chars_dupe_6grams": 0.01710969, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01380208, "qsc_code_frac_chars_whitespace": 0.17205692, "qsc_code_size_file_byte": 4638.0, "qsc_code_num_lines": 166.0, "qsc_code_num_chars_line_max": 93.0, "qsc_code_num_chars_line_mean": 27.93975904, "qsc_code_frac_chars_alphabet": 0.83854167, "qsc_code_frac_chars_comments": 0.18779646, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05504587, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00132732, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05504587, "qsc_codejava_score_lines_no_logic": 0.24770642, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfFuror.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.rings;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import java.text.DecimalFormat;
public class RingOfFuror extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.105f, soloBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(10.5f));
}
}
@Override
protected RingBuff buff( ) {
return new Furor();
}
public static float attackDelayMultiplier(Char target ){
return 1f / (float)Math.pow(1.105, getBonus(target, Furor.class));
}
public class Furor extends RingBuff {
}
}
| 1,569 | RingOfFuror | java | en | java | code | {"qsc_code_num_words": 209, "qsc_code_num_chars": 1569.0, "qsc_code_mean_word_length": 5.49282297, "qsc_code_frac_words_unique": 0.59808612, "qsc_code_frac_chars_top_2grams": 0.02874564, "qsc_code_frac_chars_top_3grams": 0.03397213, "qsc_code_frac_chars_top_4grams": 0.04965157, "qsc_code_frac_chars_dupe_5grams": 0.07142857, "qsc_code_frac_chars_dupe_6grams": 0.04878049, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02522936, "qsc_code_frac_chars_whitespace": 0.16634799, "qsc_code_size_file_byte": 1569.0, "qsc_code_num_lines": 49.0, "qsc_code_num_chars_line_max": 118.0, "qsc_code_num_chars_line_mean": 32.02040816, "qsc_code_frac_chars_alphabet": 0.85244648, "qsc_code_frac_chars_comments": 0.49776928, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.03299492, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.13636364, "qsc_codejava_score_lines_no_logic": 0.36363636, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfAccuracy.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.rings;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import java.text.DecimalFormat;
public class RingOfAccuracy extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.3f, soloBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(30f));
}
}
@Override
protected RingBuff buff( ) {
return new Accuracy();
}
public static float accuracyMultiplier( Char target ){
return (float)Math.pow(1.3f, getBonus(target, Accuracy.class));
}
public class Accuracy extends RingBuff {
}
}
| 1,571 | RingOfAccuracy | java | en | java | code | {"qsc_code_num_words": 207, "qsc_code_num_chars": 1571.0, "qsc_code_mean_word_length": 5.56038647, "qsc_code_frac_words_unique": 0.5942029, "qsc_code_frac_chars_top_2grams": 0.02867072, "qsc_code_frac_chars_top_3grams": 0.03388358, "qsc_code_frac_chars_top_4grams": 0.04952215, "qsc_code_frac_chars_dupe_5grams": 0.0712424, "qsc_code_frac_chars_dupe_6grams": 0.04865334, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02062643, "qsc_code_frac_chars_whitespace": 0.16677276, "qsc_code_size_file_byte": 1571.0, "qsc_code_num_lines": 49.0, "qsc_code_num_chars_line_max": 116.0, "qsc_code_num_chars_line_mean": 32.06122449, "qsc_code_frac_chars_alphabet": 0.85867074, "qsc_code_frac_chars_comments": 0.49713558, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.03291139, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.13636364, "qsc_codejava_score_lines_no_logic": 0.36363636, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfWealth.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.rings;
import com.shatteredpixel.shatteredpixeldungeon.Challenges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Gold;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.AlchemicalCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfExperience;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTransmutation;
import com.shatteredpixel.shatteredpixeldungeon.items.spells.ArcaneCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfEnchantment;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashSet;
public class RingOfWealth extends Ring {
private float triesToDrop = Float.MIN_VALUE;
private int dropsToRare = Integer.MIN_VALUE;
public static boolean latestDropWasRare = false;
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (Math.pow(1.2f, soloBonus()) - 1f)));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(20f));
}
}
private static final String TRIES_TO_DROP = "tries_to_drop";
private static final String DROPS_TO_RARE = "drops_to_rare";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put(TRIES_TO_DROP, triesToDrop);
bundle.put(DROPS_TO_RARE, dropsToRare);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
triesToDrop = bundle.getFloat(TRIES_TO_DROP);
dropsToRare = bundle.getInt(DROPS_TO_RARE);
}
@Override
protected RingBuff buff( ) {
return new Wealth();
}
public static float dropChanceMultiplier( Char target ){
return (float)Math.pow(1.2, getBonus(target, Wealth.class));
}
public static ArrayList<Item> tryForBonusDrop(Char target, int tries ){
if (getBonus(target, Wealth.class) <= 0) return null;
HashSet<Wealth> buffs = target.buffs(Wealth.class);
float triesToDrop = Float.MIN_VALUE;
int dropsToRare = Integer.MIN_VALUE;
//find the largest count (if they aren't synced yet)
for (Wealth w : buffs){
if (w.triesToDrop() > triesToDrop){
triesToDrop = w.triesToDrop();
dropsToRare = w.dropsToRare();
}
}
//reset (if needed), decrement, and store counts
if (triesToDrop == Float.MIN_VALUE) {
triesToDrop = Random.NormalIntRange(0, 50);
dropsToRare = Random.NormalIntRange(5, 10);
}
//now handle reward logic
ArrayList<Item> drops = new ArrayList<>();
triesToDrop -= dropProgression(target, tries);
while ( triesToDrop <= 0 ){
if (dropsToRare <= 0){
Item i;
do {
i = genRareDrop();
} while (Challenges.isItemBlocked(i));
drops.add(i);
latestDropWasRare = true;
dropsToRare = Random.NormalIntRange(5, 10);
} else {
Item i;
do {
i = genStandardDrop();
} while (Challenges.isItemBlocked(i));
drops.add(i);
dropsToRare--;
}
triesToDrop += Random.NormalIntRange(0, 50);
}
//store values back into rings
for (Wealth w : buffs){
w.triesToDrop(triesToDrop);
w.dropsToRare(dropsToRare);
}
return drops;
}
public static Item genStandardDrop(){
float roll = Random.Float();
if (roll < 0.3f){ //30% chance
Item result = new Gold().random();
result.quantity(Math.round(result.quantity() * Random.NormalFloat(0.33f, 1f)));
return result;
} else if (roll < 0.7f){ //40% chance
return genBasicConsumable();
} else if (roll < 0.9f){ //20% chance
return genExoticConsumable();
} else { //10% chance
if (Random.Int(3) != 0){
Weapon weapon = Generator.randomWeapon();
weapon.enchant(null);
weapon.cursed = false;
weapon.cursedKnown = true;
weapon.level(0);
return weapon;
} else {
Armor armor = Generator.randomArmor();
armor.inscribe(null);
armor.cursed = false;
armor.cursedKnown = true;
armor.level(0);
return armor;
}
}
}
private static Item genBasicConsumable(){
float roll = Random.Float();
if (roll < 0.4f){ //40% chance
return Generator.random(Generator.Category.STONE);
} else if (roll < 0.7f){ //30% chance
return Generator.random(Generator.Category.POTION);
} else { //30% chance
return Generator.random(Generator.Category.SCROLL);
}
}
private static Item genExoticConsumable(){
float roll = Random.Float();
if (roll < 0.3f){ //30% chance
return Generator.random(Generator.Category.POTION);
} else if (roll < 0.6f) { //30% chance
return Generator.random(Generator.Category.SCROLL);
} else { //40% chance
return Random.Int(2) == 0 ? new AlchemicalCatalyst() : new ArcaneCatalyst();
}
}
public static Item genRareDrop(){
float roll = Random.Float();
if (roll < 0.3f){ //30% chance
Item result = new Gold().random();
result.quantity(Math.round(result.quantity() * Random.NormalFloat(3f, 6f)));
return result;
} else if (roll < 0.7f){ //40% chance
return genHighValueConsumable();
} else if (roll < 0.9f){ //20% chance
Item result = Random.Int(2) == 0 ? Generator.random(Generator.Category.ARTIFACT) : Generator.random(Generator.Category.RING);
result.cursed = false;
result.cursedKnown = true;
return result;
} else { //10% chance
if (Random.Int(3) != 0){
Weapon weapon = Generator.randomWeapon((Dungeon.depth / 5) + 1);
weapon.upgrade(1);
weapon.enchant(Weapon.Enchantment.random());
weapon.cursed = false;
weapon.cursedKnown = true;
return weapon;
} else {
Armor armor = Generator.randomArmor((Dungeon.depth / 5) + 1);
armor.upgrade();
armor.inscribe(Armor.Glyph.random());
armor.cursed = false;
armor.cursedKnown = true;
return armor;
}
}
}
private static Item genHighValueConsumable(){
switch( Random.Int(4) ){ //25% chance each
case 0: default:
return new StoneOfEnchantment();
case 1:
return new StoneOfEnchantment().quantity(2);
case 2:
return new PotionOfExperience();
case 3:
return new ScrollOfTransmutation();
}
}
private static float dropProgression( Char target, int tries ){
return tries * (float)Math.pow(1.2f, getBonus(target, Wealth.class) );
}
public class Wealth extends RingBuff {
private void triesToDrop( float val ){
triesToDrop = val;
}
private float triesToDrop(){
return triesToDrop;
}
private void dropsToRare( int val ) {
dropsToRare = val;
}
private int dropsToRare(){
return dropsToRare;
}
}
}
| 7,816 | RingOfWealth | java | en | java | code | {"qsc_code_num_words": 921, "qsc_code_num_chars": 7816.0, "qsc_code_mean_word_length": 5.9815418, "qsc_code_frac_words_unique": 0.26927253, "qsc_code_frac_chars_top_2grams": 0.02613905, "qsc_code_frac_chars_top_3grams": 0.10346705, "qsc_code_frac_chars_top_4grams": 0.11181703, "qsc_code_frac_chars_dupe_5grams": 0.37484117, "qsc_code_frac_chars_dupe_6grams": 0.22944273, "qsc_code_frac_chars_dupe_7grams": 0.16409512, "qsc_code_frac_chars_dupe_8grams": 0.12107461, "qsc_code_frac_chars_dupe_9grams": 0.10219641, "qsc_code_frac_chars_dupe_10grams": 0.08331821, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01871327, "qsc_code_frac_chars_whitespace": 0.17272262, "qsc_code_size_file_byte": 7816.0, "qsc_code_num_lines": 258.0, "qsc_code_num_chars_line_max": 129.0, "qsc_code_num_chars_line_mean": 30.29457364, "qsc_code_frac_chars_alphabet": 0.83328178, "qsc_code_frac_chars_comments": 0.14342375, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.28571429, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00776699, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08866995, "qsc_codejava_score_lines_no_logic": 0.25123153, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/rings/RingOfElements.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.rings;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Electricity;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Charm;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Corrosion;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Ooze;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Weakness;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Eye;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Shaman;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Warlock;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Yog;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfBlastWave;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfDisintegration;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfFireblast;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfFrost;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfLightning;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfLivingEarth;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfMagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfPrismaticLight;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfTransfusion;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfWarding;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.DisintegrationTrap;
import com.shatteredpixel.shatteredpixeldungeon.levels.traps.GrimTrap;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import java.text.DecimalFormat;
import java.util.HashSet;
public class RingOfElements extends Ring {
public String statsInfo() {
if (isIdentified()){
return Messages.get(this, "stats", new DecimalFormat("#.##").format(100f * (1f - Math.pow(0.80f, soloBonus()))));
} else {
return Messages.get(this, "typical_stats", new DecimalFormat("#.##").format(20f));
}
}
@Override
protected RingBuff buff( ) {
return new Resistance();
}
public static final HashSet<Class> RESISTS = new HashSet<>();
static {
RESISTS.add( Burning.class );
RESISTS.add( Charm.class );
RESISTS.add( Chill.class );
RESISTS.add( Frost.class );
RESISTS.add( Ooze.class );
RESISTS.add( Paralysis.class );
RESISTS.add( Poison.class );
RESISTS.add( Corrosion.class );
RESISTS.add( Weakness.class );
RESISTS.add( DisintegrationTrap.class );
RESISTS.add( GrimTrap.class );
RESISTS.add( WandOfBlastWave.class );
RESISTS.add( WandOfDisintegration.class );
RESISTS.add( WandOfFireblast.class );
RESISTS.add( WandOfFrost.class );
RESISTS.add( WandOfLightning.class );
RESISTS.add( WandOfLivingEarth.class );
RESISTS.add( WandOfMagicMissile.class );
RESISTS.add( WandOfPrismaticLight.class );
RESISTS.add( WandOfTransfusion.class );
RESISTS.add( WandOfWarding.Ward.class );
RESISTS.add( ToxicGas.class );
RESISTS.add( Electricity.class );
RESISTS.add( Shaman.LightningBolt.class );
RESISTS.add( Warlock.DarkBolt.class );
RESISTS.add( Eye.DeathGaze.class );
RESISTS.add( Yog.BurningFist.DarkBolt.class );
}
public static float resist( Char target, Class effect ){
if (getBonus(target, Resistance.class) == 0) return 1f;
for (Class c : RESISTS){
if (c.isAssignableFrom(effect)){
return (float)Math.pow(0.80, getBonus(target, Resistance.class));
}
}
return 1f;
}
public class Resistance extends RingBuff {
}
}
| 4,833 | RingOfElements | java | en | java | code | {"qsc_code_num_words": 543, "qsc_code_num_chars": 4833.0, "qsc_code_mean_word_length": 7.02394107, "qsc_code_frac_words_unique": 0.31123389, "qsc_code_frac_chars_top_2grams": 0.13371788, "qsc_code_frac_chars_top_3grams": 0.29889879, "qsc_code_frac_chars_top_4grams": 0.3345569, "qsc_code_frac_chars_dupe_5grams": 0.42029365, "qsc_code_frac_chars_dupe_6grams": 0.40036707, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00742287, "qsc_code_frac_chars_whitespace": 0.10800745, "qsc_code_size_file_byte": 4833.0, "qsc_code_num_lines": 121.0, "qsc_code_num_chars_line_max": 117.0, "qsc_code_num_chars_line_mean": 39.94214876, "qsc_code_frac_chars_alphabet": 0.87729065, "qsc_code_frac_chars_comments": 0.16159735, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00641658, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03488372, "qsc_codejava_score_lines_no_logic": 0.43023256, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfIdentify.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.effects.Identification;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class ScrollOfIdentify extends InventoryScroll {
{
initials = 0;
mode = WndBag.Mode.UNIDENTIFED;
bones = true;
}
@Override
public void empoweredRead() {
ArrayList<Item> unIDed = new ArrayList<>();
for( Item i : curUser.belongings){
if (!i.isIdentified()){
unIDed.add(i);
}
}
if (unIDed.size() > 1) {
Random.element(unIDed).identify();
Sample.INSTANCE.play( Assets.SND_TELEPORT );
}
doRead();
}
@Override
protected void onItemSelected( Item item ) {
curUser.sprite.parent.add( new Identification( curUser.sprite.center().offset( 0, -16 ) ) );
item.identify();
GLog.i( Messages.get(this, "it_is", item) );
Badges.validateItemLevelAquired( item );
}
@Override
public int price() {
return isKnown() ? 30 * quantity : super.price();
}
}
| 2,204 | ScrollOfIdentify | java | en | java | code | {"qsc_code_num_words": 271, "qsc_code_num_chars": 2204.0, "qsc_code_mean_word_length": 6.00369004, "qsc_code_frac_words_unique": 0.54612546, "qsc_code_frac_chars_top_2grams": 0.04978488, "qsc_code_frac_chars_top_3grams": 0.18684696, "qsc_code_frac_chars_top_4grams": 0.18930547, "qsc_code_frac_chars_dupe_5grams": 0.05039951, "qsc_code_frac_chars_dupe_6grams": 0.03441918, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01296596, "qsc_code_frac_chars_whitespace": 0.16016334, "qsc_code_size_file_byte": 2204.0, "qsc_code_num_lines": 77.0, "qsc_code_num_chars_line_max": 95.0, "qsc_code_num_chars_line_mean": 28.62337662, "qsc_code_frac_chars_alphabet": 0.86601837, "qsc_code_frac_chars_comments": 0.35435572, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.06976744, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0035137, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09302326, "qsc_codejava_score_lines_no_logic": 0.34883721, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMagicMapping.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MindVision;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
public class ScrollOfMagicMapping extends Scroll {
{
initials = 2;
}
@Override
public void doRead() {
int length = Dungeon.level.length();
int[] map = Dungeon.level.map;
boolean[] mapped = Dungeon.level.mapped;
boolean[] discoverable = Dungeon.level.discoverable;
boolean noticed = false;
for (int i=0; i < length; i++) {
int terr = map[i];
if (discoverable[i]) {
mapped[i] = true;
if ((Terrain.flags[terr] & Terrain.SECRET) != 0) {
Dungeon.level.discover( i );
if (Dungeon.level.heroFOV[i]) {
GameScene.discoverTile( i, terr );
discover( i );
noticed = true;
}
}
}
}
GameScene.updateFog();
GLog.i( Messages.get(this, "layout") );
if (noticed) {
Sample.INSTANCE.play( Assets.SND_SECRET );
}
SpellSprite.show( curUser, SpellSprite.MAP );
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
setKnown();
readAnimation();
}
@Override
public void empoweredRead() {
doRead();
Buff.affect( curUser, MindVision.class, MindVision.DURATION );
Buff.affect( curUser, Awareness.class, Awareness.DURATION );
Dungeon.observe();
}
@Override
public int price() {
return isKnown() ? 40 * quantity : super.price();
}
public static void discover( int cell ) {
CellEmitter.get( cell ).start( Speck.factory( Speck.DISCOVER ), 0.1f, 4 );
}
}
| 3,151 | ScrollOfMagicMapping | java | en | java | code | {"qsc_code_num_words": 367, "qsc_code_num_chars": 3151.0, "qsc_code_mean_word_length": 6.26975477, "qsc_code_frac_words_unique": 0.44141689, "qsc_code_frac_chars_top_2grams": 0.10343329, "qsc_code_frac_chars_top_3grams": 0.23120382, "qsc_code_frac_chars_top_4grams": 0.24858757, "qsc_code_frac_chars_dupe_5grams": 0.22120817, "qsc_code_frac_chars_dupe_6grams": 0.11994785, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00949487, "qsc_code_frac_chars_whitespace": 0.16439226, "qsc_code_size_file_byte": 3151.0, "qsc_code_num_lines": 106.0, "qsc_code_num_chars_line_max": 77.0, "qsc_code_num_chars_line_mean": 29.72641509, "qsc_code_frac_chars_alphabet": 0.86441322, "qsc_code_frac_chars_comments": 0.24785782, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04545455, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00253165, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07575758, "qsc_codejava_score_lines_no_logic": 0.3030303, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/Scroll.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicImmune;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.ItemStatusHandler;
import com.shatteredpixel.shatteredpixeldungeon.items.Recipe;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.UnstableSpellbook;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ExoticScroll;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ScrollOfAntiMagic;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfAffection;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfAggression;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfAugmentation;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfBlast;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfBlink;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfClairvoyance;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfDeepenedSleep;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfDisarming;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfEnchantment;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfFlock;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfIntuition;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.StoneOfShock;
import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.utils.Bundle;
import com.watabou.utils.Reflection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public abstract class Scroll extends Item {
public static final String AC_READ = "READ";
protected static final float TIME_TO_READ = 1f;
protected Integer initials;
private static final Class<?>[] scrolls = {
ScrollOfIdentify.class,
ScrollOfMagicMapping.class,
ScrollOfRecharging.class,
ScrollOfRemoveCurse.class,
ScrollOfTeleportation.class,
ScrollOfUpgrade.class,
ScrollOfRage.class,
ScrollOfTerror.class,
ScrollOfLullaby.class,
ScrollOfTransmutation.class,
ScrollOfRetribution.class,
ScrollOfMirrorImage.class
};
private static final HashMap<String, Integer> runes = new HashMap<String, Integer>() {
{
put("KAUNAN",ItemSpriteSheet.SCROLL_KAUNAN);
put("SOWILO",ItemSpriteSheet.SCROLL_SOWILO);
put("LAGUZ",ItemSpriteSheet.SCROLL_LAGUZ);
put("YNGVI",ItemSpriteSheet.SCROLL_YNGVI);
put("GYFU",ItemSpriteSheet.SCROLL_GYFU);
put("RAIDO",ItemSpriteSheet.SCROLL_RAIDO);
put("ISAZ",ItemSpriteSheet.SCROLL_ISAZ);
put("MANNAZ",ItemSpriteSheet.SCROLL_MANNAZ);
put("NAUDIZ",ItemSpriteSheet.SCROLL_NAUDIZ);
put("BERKANAN",ItemSpriteSheet.SCROLL_BERKANAN);
put("ODAL",ItemSpriteSheet.SCROLL_ODAL);
put("TIWAZ",ItemSpriteSheet.SCROLL_TIWAZ);
}
};
protected static ItemStatusHandler<Scroll> handler;
protected String rune;
{
stackable = true;
defaultAction = AC_READ;
}
@SuppressWarnings("unchecked")
public static void initLabels() {
handler = new ItemStatusHandler<>( (Class<? extends Scroll>[])scrolls, runes );
}
public static void save( Bundle bundle ) {
handler.save( bundle );
}
public static void saveSelectively( Bundle bundle, ArrayList<Item> items ) {
ArrayList<Class<?extends Item>> classes = new ArrayList<>();
for (Item i : items){
if (i instanceof ExoticScroll){
if (!classes.contains(ExoticScroll.exoToReg.get(i.getClass()))){
classes.add(ExoticScroll.exoToReg.get(i.getClass()));
}
} else if (i instanceof Scroll){
if (!classes.contains(i.getClass())){
classes.add(i.getClass());
}
}
}
handler.saveClassesSelectively( bundle, classes );
}
@SuppressWarnings("unchecked")
public static void restore( Bundle bundle ) {
handler = new ItemStatusHandler<>( (Class<? extends Scroll>[])scrolls, runes, bundle );
}
public Scroll() {
super();
reset();
}
//anonymous scrolls are always IDed, do not affect ID status,
//and their sprite is replaced by a placeholder if they are not known,
//useful for items that appear in UIs, or which are only spawned for their effects
protected boolean anonymous = false;
public void anonymize(){
if (!isKnown()) image = ItemSpriteSheet.SCROLL_HOLDER;
anonymous = true;
}
@Override
public void reset(){
super.reset();
if (handler != null && handler.contains(this)) {
image = handler.image(this);
rune = handler.label(this);
}
}
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
actions.add( AC_READ );
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute( hero, action );
if (action.equals( AC_READ )) {
if (hero.buff(MagicImmune.class) != null){
GLog.w( Messages.get(this, "no_magic") );
} else if (hero.buff( Blindness.class ) != null) {
GLog.w( Messages.get(this, "blinded") );
} else if (hero.buff(UnstableSpellbook.bookRecharge.class) != null
&& hero.buff(UnstableSpellbook.bookRecharge.class).isCursed()
&& !(this instanceof ScrollOfRemoveCurse || this instanceof ScrollOfAntiMagic)){
GLog.n( Messages.get(this, "cursed") );
} else {
curUser = hero;
curItem = detach( hero.belongings.backpack );
doRead();
}
}
}
public abstract void doRead();
//currently unused. Used to be used for unstable spellbook prior to 0.7.0
public void empoweredRead(){}
protected void readAnimation() {
curUser.spend( TIME_TO_READ );
curUser.busy();
((HeroSprite)curUser.sprite).read();
}
public boolean isKnown() {
return anonymous || (handler != null && handler.isKnown( this ));
}
public void setKnown() {
if (!anonymous) {
if (!isKnown()) {
handler.know(this);
updateQuickslot();
}
if (Dungeon.hero.isAlive()) {
Catalog.setSeen(getClass());
}
}
}
@Override
public Item identify() {
setKnown();
return super.identify();
}
@Override
public String name() {
return isKnown() ? name : Messages.get(this, rune);
}
@Override
public String info() {
return isKnown() ?
desc() :
Messages.get(this, "unknown_desc");
}
public Integer initials(){
return isKnown() ? initials : null;
}
@Override
public boolean isUpgradable() {
return false;
}
@Override
public boolean isIdentified() {
return isKnown();
}
public static HashSet<Class<? extends Scroll>> getKnown() {
return handler.known();
}
public static HashSet<Class<? extends Scroll>> getUnknown() {
return handler.unknown();
}
public static boolean allKnown() {
return handler.known().size() == scrolls.length;
}
@Override
public int price() {
return 30 * quantity;
}
public static class PlaceHolder extends Scroll {
{
image = ItemSpriteSheet.SCROLL_HOLDER;
}
@Override
public boolean isSimilar(Item item) {
return ExoticScroll.regToExo.containsKey(item.getClass())
|| ExoticScroll.regToExo.containsValue(item.getClass());
}
@Override
public void doRead() {}
@Override
public String info() {
return "";
}
}
public static class ScrollToStone extends Recipe {
private static HashMap<Class<?extends Scroll>, Class<?extends Runestone>> stones = new HashMap<>();
private static HashMap<Class<?extends Scroll>, Integer> amnts = new HashMap<>();
static {
stones.put(ScrollOfIdentify.class, StoneOfIntuition.class);
amnts.put(ScrollOfIdentify.class, 3);
stones.put(ScrollOfLullaby.class, StoneOfDeepenedSleep.class);
amnts.put(ScrollOfLullaby.class, 3);
stones.put(ScrollOfMagicMapping.class, StoneOfClairvoyance.class);
amnts.put(ScrollOfMagicMapping.class, 3);
stones.put(ScrollOfMirrorImage.class, StoneOfFlock.class);
amnts.put(ScrollOfMirrorImage.class, 3);
stones.put(ScrollOfRetribution.class, StoneOfBlast.class);
amnts.put(ScrollOfRetribution.class, 2);
stones.put(ScrollOfRage.class, StoneOfAggression.class);
amnts.put(ScrollOfRage.class, 3);
stones.put(ScrollOfRecharging.class, StoneOfShock.class);
amnts.put(ScrollOfRecharging.class, 2);
stones.put(ScrollOfRemoveCurse.class, StoneOfDisarming.class);
amnts.put(ScrollOfRemoveCurse.class, 2);
stones.put(ScrollOfTeleportation.class, StoneOfBlink.class);
amnts.put(ScrollOfTeleportation.class, 2);
stones.put(ScrollOfTerror.class, StoneOfAffection.class);
amnts.put(ScrollOfTerror.class, 3);
stones.put(ScrollOfTransmutation.class, StoneOfAugmentation.class);
amnts.put(ScrollOfTransmutation.class, 2);
stones.put(ScrollOfUpgrade.class, StoneOfEnchantment.class);
amnts.put(ScrollOfUpgrade.class, 2);
}
@Override
public boolean testIngredients(ArrayList<Item> ingredients) {
if (ingredients.size() != 1
|| !ingredients.get(0).isIdentified()
|| !(ingredients.get(0) instanceof Scroll)
|| !stones.containsKey(ingredients.get(0).getClass())){
return false;
}
return true;
}
@Override
public int cost(ArrayList<Item> ingredients) {
return 0;
}
@Override
public Item brew(ArrayList<Item> ingredients) {
if (!testIngredients(ingredients)) return null;
Scroll s = (Scroll) ingredients.get(0);
s.quantity(s.quantity() - 1);
return Reflection.newInstance(stones.get(s.getClass())).quantity(amnts.get(s.getClass()));
}
@Override
public Item sampleOutput(ArrayList<Item> ingredients) {
if (!testIngredients(ingredients)) return null;
Scroll s = (Scroll) ingredients.get(0);
return Reflection.newInstance(stones.get(s.getClass())).quantity(amnts.get(s.getClass()));
}
}
}
| 11,230 | Scroll | java | en | java | code | {"qsc_code_num_words": 1196, "qsc_code_num_chars": 11230.0, "qsc_code_mean_word_length": 6.85284281, "qsc_code_frac_words_unique": 0.24498328, "qsc_code_frac_chars_top_2grams": 0.0329429, "qsc_code_frac_chars_top_3grams": 0.13445583, "qsc_code_frac_chars_top_4grams": 0.15031723, "qsc_code_frac_chars_dupe_5grams": 0.28806735, "qsc_code_frac_chars_dupe_6grams": 0.20095168, "qsc_code_frac_chars_dupe_7grams": 0.07515861, "qsc_code_frac_chars_dupe_8grams": 0.05295266, "qsc_code_frac_chars_dupe_9grams": 0.03904344, "qsc_code_frac_chars_dupe_10grams": 0.03904344, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00452632, "qsc_code_frac_chars_whitespace": 0.15405165, "qsc_code_size_file_byte": 11230.0, "qsc_code_num_lines": 368.0, "qsc_code_num_chars_line_max": 102.0, "qsc_code_num_chars_line_mean": 30.51630435, "qsc_code_frac_chars_alphabet": 0.85821053, "qsc_code_frac_chars_comments": 0.09501336, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10869565, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01170914, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.10869565, "qsc_codejava_score_lines_no_logic": 0.26449275, "qsc_codejava_frac_words_no_modifier": 0.83870968, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | CHANGELOG | Version 0.4
===========
+ License changed to GPL (v3) to comply with terms of the GPL for use of PyBluez.
+ Fixed memory leak issues on Mac OS X when deallocating objects created with pyobjc.
+ Fixed finddevices() on Mac OS X to not thrown an exception if no devices are found.
Version 0.3.3
=============
+ Deprecation warnings no longer appear for Mac OS 10.5.
+ Fixed sockets to raise socket.timeout correctly.
+ Fixed bugs in connect() & disconnect() in OBEXClient for both Mac & Linux.
+ Fixed OBEX transfer speed for OBEXClient on Linux.
Version 0.3.2
=============
+ Fixed so doesn't raise exception when using 'from lightblue import *'.
+ For Linux: fixed bug where lightblue.obex.recvfile() was often refusing requests.
+ For Mac: fixed bug where NSInconsistencyException was being raised while blocking/processing events.
Version 0.3.1
=============
+ This fixes a bug in findservices() on Python for Series 60.
Version 0.3
===========
+ A new OBEXClient class for Mac OS X and Linux. It can send all the usual OBEX requests, with any type of headers (including custom headers). There is a new obex_ftp_client.py example that uses OBEXClient to implement an OBEX File Transfer client.
+ The library now works on Mac OS 10.5. Currently there are some deprecation warnings when you import lightblue, but there shouldn't be any issues otherwise.
+ The BTUtil framework has been renamed to "LightAquaBlue", and its OBEX-related classes have been completely rewritten; it now has a much better, more flexible API, that makes it possible to use it to build higher-level OBEX implementations.
+ The Linux version's internal OBEX code has been completely rewritten, and it's now much easier to customise and tweak the OBEX client and server implementations, if necessary.
+ The lightblue.obex sendfile() and recvfile() functions now accept any old file-like objects, instead of only accepting built-in file objects with proper file descriptors.
+ Fixed various unicode-related bugs.
Version 0.2.3
=============
+ Fixed Linux version to work with newer versions of PyBluez
Version 0.2.2
=============
+ The PyS60 3rd Edition binaries have (really) been fixed, and gethostaddr() and gethostclass() should also be fixed for PyS60 2nd Edition FP2 and FP3.
+ Since it's getting more difficult to build for PyS60 1st Edition, this build has been dropped for this version -- which isn't an issue for this release since there are no new features -- but there won't be any further builds for this edition. If you need to compile LightBlue for 1st Edition, feel free to email me with any issues.
+ Fixed functions on Mac OS X build that wait (e.g. finddevices(), recv() for sockets) so that they don't busy-wait and hog the CPU.
Version 0.2.1
=============
+ Hopefully fixed problems with PyS60 3rd Edition sisx binary
+ Added unsigned sis for PyS60 3rd Edition with maximum free dev cert capabilities
Version 0.2
===========
+ L2CAP client sockets for Mac OS X and Linux
+ finddevicename() now takes usecache argument to specify whether to do a remote name request if name is in local cache
+ stopadvertising() is now automatically called for a socket when close() is called on the socket
+ Added SIS build for Series 60 3rd Edition
+ If some of the SIS files for PyS60 didn't work before, they should now
+ Improved buffering of received data for sockets on Mac OS X
+ Fixed recv() for mac sockets if other side has closed connection
+ Fixed mac sockets to receive binary data
| 3,489 | CHANGELOG | en | unknown | unknown | {} | 0 | {} | |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/SandalsOfNature.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Roots;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.EarthParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Earthroot;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.Camera;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
import java.util.Collections;
public class SandalsOfNature extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_SANDALS;
levelCap = 3;
charge = 0;
defaultAction = AC_ROOT;
}
public static final String AC_FEED = "FEED";
public static final String AC_ROOT = "ROOT";
protected WndBag.Mode mode = WndBag.Mode.SEED;
public ArrayList<Class> seeds = new ArrayList<>();
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (isEquipped( hero ) && level() < 3 && !cursed)
actions.add(AC_FEED);
if (isEquipped( hero ) && charge > 0)
actions.add(AC_ROOT);
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute(hero, action);
if (action.equals(AC_FEED)){
GameScene.selectItem(itemSelector, mode, Messages.get(this, "prompt"));
} else if (action.equals(AC_ROOT) && level() > 0){
if (!isEquipped( hero )) GLog.i( Messages.get(Artifact.class, "need_to_equip") );
else if (charge == 0) GLog.i( Messages.get(this, "no_charge") );
else {
Buff.prolong(hero, Roots.class, 5);
Buff.affect(hero, Earthroot.Armor.class).level(charge);
CellEmitter.bottom(hero.pos).start(EarthParticle.FACTORY, 0.05f, 8);
Camera.main.shake(1, 0.4f);
charge = 0;
updateQuickslot();
}
}
}
@Override
protected ArtifactBuff passiveBuff() {
return new Naturalism();
}
@Override
public void charge(Hero target) {
target.buff(Naturalism.class).charge();
}
@Override
public String desc() {
String desc = Messages.get(this, "desc_" + (level()+1));
if ( isEquipped ( Dungeon.hero ) ){
desc += "\n\n";
if (!cursed)
desc += Messages.get(this, "desc_hint");
else
desc += Messages.get(this, "desc_cursed");
if (level() > 0)
desc += "\n\n" + Messages.get(this, "desc_ability");
}
if (!seeds.isEmpty()){
desc += "\n\n" + Messages.get(this, "desc_seeds", seeds.size());
}
return desc;
}
@Override
public Item upgrade() {
if (level() < 0) image = ItemSpriteSheet.ARTIFACT_SANDALS;
else if (level() == 0) image = ItemSpriteSheet.ARTIFACT_SHOES;
else if (level() == 1) image = ItemSpriteSheet.ARTIFACT_BOOTS;
else if (level() >= 2) image = ItemSpriteSheet.ARTIFACT_GREAVES;
name = Messages.get(this, "name_" + (level()+1));
return super.upgrade();
}
private static final String SEEDS = "seeds";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle(bundle);
bundle.put(SEEDS, seeds.toArray(new Class[seeds.size()]));
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle(bundle);
if (level() > 0) name = Messages.get(this, "name_" + level());
if (bundle.contains(SEEDS))
Collections.addAll(seeds , bundle.getClassArray(SEEDS));
if (level() == 1) image = ItemSpriteSheet.ARTIFACT_SHOES;
else if (level() == 2) image = ItemSpriteSheet.ARTIFACT_BOOTS;
else if (level() >= 3) image = ItemSpriteSheet.ARTIFACT_GREAVES;
}
public class Naturalism extends ArtifactBuff{
public void charge() {
if (level() > 0 && charge < target.HT){
//gain 1+(1*level)% of the difference between current charge and max HP.
charge+= (Math.round( (target.HT-charge) * (.01+ level()*0.01) ));
updateQuickslot();
}
}
}
protected WndBag.Listener itemSelector = new WndBag.Listener() {
@Override
public void onSelect( Item item ) {
if (item != null && item instanceof Plant.Seed) {
if (seeds.contains(item.getClass())){
GLog.w( Messages.get(SandalsOfNature.class, "already_fed") );
} else {
seeds.add(item.getClass());
Hero hero = Dungeon.hero;
hero.sprite.operate( hero.pos );
Sample.INSTANCE.play( Assets.SND_PLANT );
hero.busy();
hero.spend( 2f );
if (seeds.size() >= 3+(level()*3)){
seeds.clear();
upgrade();
if (level() >= 1 && level() <= 3) {
GLog.p( Messages.get(SandalsOfNature.class, "levelup") );
}
} else {
GLog.i( Messages.get(SandalsOfNature.class, "absorb_seed") );
}
item.detach(hero.belongings.backpack);
}
}
}
};
}
| 6,119 | SandalsOfNature | java | en | java | code | {"qsc_code_num_words": 739, "qsc_code_num_chars": 6119.0, "qsc_code_mean_word_length": 5.78078484, "qsc_code_frac_words_unique": 0.31529093, "qsc_code_frac_chars_top_2grams": 0.03792135, "qsc_code_frac_chars_top_3grams": 0.1423221, "qsc_code_frac_chars_top_4grams": 0.15449438, "qsc_code_frac_chars_dupe_5grams": 0.21722846, "qsc_code_frac_chars_dupe_6grams": 0.12429775, "qsc_code_frac_chars_dupe_7grams": 0.05992509, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01097609, "qsc_code_frac_chars_whitespace": 0.16620363, "qsc_code_size_file_byte": 6119.0, "qsc_code_num_lines": 200.0, "qsc_code_num_chars_line_max": 85.0, "qsc_code_num_chars_line_mean": 30.595, "qsc_code_frac_chars_alphabet": 0.82634261, "qsc_code_frac_chars_comments": 0.13940186, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10344828, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.02639575, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06206897, "qsc_codejava_score_lines_no_logic": 0.22758621, "qsc_codejava_frac_words_no_modifier": 0.81818182, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | examples/LightAquaBlue/SimpleOBEXClient/SimpleOBEXClient.xcodeproj/project.pbxproj | // !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 42;
objects = {
/* Begin PBXBuildFile section */
817D221B0D3DAA1C00469B5D /* IOBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 817D221A0D3DAA1C00469B5D /* IOBluetooth.framework */; };
81D36BF10D320BED00C2AF19 /* SimpleOBEXClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 81D36BF00D320BED00C2AF19 /* SimpleOBEXClient.m */; };
81D36C1A0D320E1000C2AF19 /* LightAquaBlue.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81D36C190D320E1000C2AF19 /* LightAquaBlue.framework */; };
81D36C660D32573B00C2AF19 /* IOBluetoothUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 81D36C650D32573B00C2AF19 /* IOBluetoothUI.framework */; };
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* SimpleOBEXClient_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleOBEXClient_Prefix.pch; sourceTree = "<group>"; };
817D221A0D3DAA1C00469B5D /* IOBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOBluetooth.framework; path = /System/Library/Frameworks/IOBluetooth.framework; sourceTree = "<absolute>"; };
81D36BEF0D320BED00C2AF19 /* SimpleOBEXClient.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SimpleOBEXClient.h; sourceTree = "<group>"; };
81D36BF00D320BED00C2AF19 /* SimpleOBEXClient.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SimpleOBEXClient.m; sourceTree = "<group>"; };
81D36C190D320E1000C2AF19 /* LightAquaBlue.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LightAquaBlue.framework; path = /Library/Frameworks/LightAquaBlue.framework; sourceTree = "<absolute>"; };
81D36C650D32573B00C2AF19 /* IOBluetoothUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOBluetoothUI.framework; path = /System/Library/Frameworks/IOBluetoothUI.framework; sourceTree = "<absolute>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* SimpleOBEXClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SimpleOBEXClient.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8D11072E0486CEB800E47090 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
81D36C1A0D320E1000C2AF19 /* LightAquaBlue.framework in Frameworks */,
81D36C660D32573B00C2AF19 /* IOBluetoothUI.framework in Frameworks */,
817D221B0D3DAA1C00469B5D /* IOBluetooth.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
);
name = Classes;
sourceTree = "<group>";
};
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
};
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
isa = PBXGroup;
children = (
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */,
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8D1107320486CEB800E47090 /* SimpleOBEXClient.app */,
);
name = Products;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* SimpleOBEXClient */ = {
isa = PBXGroup;
children = (
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
name = SimpleOBEXClient;
sourceTree = "<group>";
};
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
32CA4F630368D1EE00C91783 /* SimpleOBEXClient_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
81D36BEF0D320BED00C2AF19 /* SimpleOBEXClient.h */,
81D36BF00D320BED00C2AF19 /* SimpleOBEXClient.m */,
);
name = "Other Sources";
sourceTree = "<group>";
};
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
8D1107310486CEB800E47090 /* Info.plist */,
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
);
name = Resources;
sourceTree = "<group>";
};
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
817D221A0D3DAA1C00469B5D /* IOBluetooth.framework */,
81D36C650D32573B00C2AF19 /* IOBluetoothUI.framework */,
81D36C190D320E1000C2AF19 /* LightAquaBlue.framework */,
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8D1107260486CEB800E47090 /* SimpleOBEXClient */ = {
isa = PBXNativeTarget;
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SimpleOBEXClient" */;
buildPhases = (
8D1107290486CEB800E47090 /* Resources */,
8D11072C0486CEB800E47090 /* Sources */,
8D11072E0486CEB800E47090 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = SimpleOBEXClient;
productInstallPath = "$(HOME)/Applications";
productName = SimpleOBEXClient;
productReference = 8D1107320486CEB800E47090 /* SimpleOBEXClient.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SimpleOBEXClient" */;
hasScannedForEncodings = 1;
mainGroup = 29B97314FDCFA39411CA2CEA /* SimpleOBEXClient */;
projectDirPath = "";
targets = (
8D1107260486CEB800E47090 /* SimpleOBEXClient */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
8D1107290486CEB800E47090 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
8D11072C0486CEB800E47090 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072D0486CEB800E47090 /* main.m in Sources */,
81D36BF10D320BED00C2AF19 /* SimpleOBEXClient.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
089C165DFE840E0CC02AAC07 /* English */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = {
isa = PBXVariantGroup;
children = (
29B97319FDCFA39411CA2CEA /* English */,
);
name = MainMenu.nib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
C01FCF4B08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = SimpleOBEXClient;
WRAPPER_EXTENSION = app;
ZERO_LINK = YES;
};
name = Debug;
};
C01FCF4C08A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_MODEL_TUNING = G5;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = SimpleOBEXClient;
WRAPPER_EXTENSION = app;
};
name = Release;
};
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SimpleOBEXClient" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4B08A954540054247B /* Debug */,
C01FCF4C08A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SimpleOBEXClient" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
C01FCF5008A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}
| 12,217 | project | pbxproj | en | unknown | unknown | {} | 0 | {} |
0-1-0/lightblue-0.4 | examples/LightAquaBlue/SimpleOBEXServer/SimpleOBEXServer.xcodeproj/project.pbxproj | // !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 42;
objects = {
/* Begin PBXBuildFile section */
817D19590D34C76C00469B5D /* SimpleOBEXServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 817D19580D34C76C00469B5D /* SimpleOBEXServer.m */; };
817D19660D34C8BF00469B5D /* LightAquaBlue.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 817D19650D34C8BF00469B5D /* LightAquaBlue.framework */; };
817D220E0D3DA9F700469B5D /* IOBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 817D220D0D3DA9F700469B5D /* IOBluetooth.framework */; };
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* SimpleOBEXServer_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleOBEXServer_Prefix.pch; sourceTree = "<group>"; };
817D19570D34C76C00469B5D /* SimpleOBEXServer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SimpleOBEXServer.h; sourceTree = "<group>"; };
817D19580D34C76C00469B5D /* SimpleOBEXServer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SimpleOBEXServer.m; sourceTree = "<group>"; };
817D19650D34C8BF00469B5D /* LightAquaBlue.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LightAquaBlue.framework; path = /Library/Frameworks/LightAquaBlue.framework; sourceTree = "<absolute>"; };
817D220D0D3DA9F700469B5D /* IOBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOBluetooth.framework; path = /System/Library/Frameworks/IOBluetooth.framework; sourceTree = "<absolute>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* SimpleOBEXServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SimpleOBEXServer.app; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8D11072E0486CEB800E47090 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */,
817D19660D34C8BF00469B5D /* LightAquaBlue.framework in Frameworks */,
817D220E0D3DA9F700469B5D /* IOBluetooth.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
);
name = Classes;
sourceTree = "<group>";
};
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
};
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */ = {
isa = PBXGroup;
children = (
29B97324FDCFA39411CA2CEA /* AppKit.framework */,
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */,
29B97325FDCFA39411CA2CEA /* Foundation.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8D1107320486CEB800E47090 /* SimpleOBEXServer.app */,
);
name = Products;
sourceTree = "<group>";
};
29B97314FDCFA39411CA2CEA /* SimpleOBEXServer */ = {
isa = PBXGroup;
children = (
080E96DDFE201D6D7F000001 /* Classes */,
29B97315FDCFA39411CA2CEA /* Other Sources */,
29B97317FDCFA39411CA2CEA /* Resources */,
29B97323FDCFA39411CA2CEA /* Frameworks */,
19C28FACFE9D520D11CA2CBB /* Products */,
);
name = SimpleOBEXServer;
sourceTree = "<group>";
};
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
32CA4F630368D1EE00C91783 /* SimpleOBEXServer_Prefix.pch */,
29B97316FDCFA39411CA2CEA /* main.m */,
817D19570D34C76C00469B5D /* SimpleOBEXServer.h */,
817D19580D34C76C00469B5D /* SimpleOBEXServer.m */,
);
name = "Other Sources";
sourceTree = "<group>";
};
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
8D1107310486CEB800E47090 /* Info.plist */,
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
);
name = Resources;
sourceTree = "<group>";
};
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
817D220D0D3DA9F700469B5D /* IOBluetooth.framework */,
817D19650D34C8BF00469B5D /* LightAquaBlue.framework */,
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8D1107260486CEB800E47090 /* SimpleOBEXServer */ = {
isa = PBXNativeTarget;
buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SimpleOBEXServer" */;
buildPhases = (
8D1107290486CEB800E47090 /* Resources */,
8D11072C0486CEB800E47090 /* Sources */,
8D11072E0486CEB800E47090 /* Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = SimpleOBEXServer;
productInstallPath = "$(HOME)/Applications";
productName = SimpleOBEXServer;
productReference = 8D1107320486CEB800E47090 /* SimpleOBEXServer.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SimpleOBEXServer" */;
hasScannedForEncodings = 1;
mainGroup = 29B97314FDCFA39411CA2CEA /* SimpleOBEXServer */;
projectDirPath = "";
targets = (
8D1107260486CEB800E47090 /* SimpleOBEXServer */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
8D1107290486CEB800E47090 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
8D11072C0486CEB800E47090 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D11072D0486CEB800E47090 /* main.m in Sources */,
817D19590D34C76C00469B5D /* SimpleOBEXServer.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
089C165DFE840E0CC02AAC07 /* English */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
29B97318FDCFA39411CA2CEA /* MainMenu.nib */ = {
isa = PBXVariantGroup;
children = (
29B97319FDCFA39411CA2CEA /* English */,
);
name = MainMenu.nib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
C01FCF4B08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = SimpleOBEXServer;
WRAPPER_EXTENSION = app;
ZERO_LINK = YES;
};
name = Debug;
};
C01FCF4C08A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_MODEL_TUNING = G5;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
PRODUCT_NAME = SimpleOBEXServer;
WRAPPER_EXTENSION = app;
};
name = Release;
};
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Debug;
};
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SimpleOBEXServer" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4B08A954540054247B /* Debug */,
C01FCF4C08A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SimpleOBEXServer" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C01FCF4F08A954540054247B /* Debug */,
C01FCF5008A954540054247B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 29B97313FDCFA39411CA2CEA /* Project object */;
}
| 11,676 | project | pbxproj | en | unknown | unknown | {} | 0 | {} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/HornOfPlenty.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Blandfruit;
import com.shatteredpixel.shatteredpixeldungeon.items.food.Food;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
public class HornOfPlenty extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_HORN1;
levelCap = 10;
charge = 0;
partialCharge = 0;
chargeCap = 10 + level();
defaultAction = AC_EAT;
}
private int storedFoodEnergy = 0;
public static final String AC_EAT = "EAT";
public static final String AC_STORE = "STORE";
protected WndBag.Mode mode = WndBag.Mode.FOOD;
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (isEquipped( hero ) && charge > 0)
actions.add(AC_EAT);
if (isEquipped( hero ) && level() < levelCap && !cursed)
actions.add(AC_STORE);
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute(hero, action);
if (action.equals(AC_EAT)){
if (!isEquipped(hero)) GLog.i( Messages.get(Artifact.class, "need_to_equip") );
else if (charge == 0) GLog.i( Messages.get(this, "no_food") );
else {
//consume as much food as it takes to be full, to a minimum of 1
Hunger hunger = Buff.affect(Dungeon.hero, Hunger.class);
int chargesToUse = Math.max( 1, hunger.hunger() / (int)(Hunger.STARVING/10));
if (chargesToUse > charge) chargesToUse = charge;
hunger.satisfy((Hunger.STARVING/10) * chargesToUse);
Food.foodProc( hero );
Statistics.foodEaten++;
charge -= chargesToUse;
hero.sprite.operate(hero.pos);
hero.busy();
SpellSprite.show(hero, SpellSprite.FOOD);
Sample.INSTANCE.play(Assets.SND_EAT);
GLog.i( Messages.get(this, "eat") );
hero.spend(Food.TIME_TO_EAT);
Badges.validateFoodEaten();
if (charge >= 15) image = ItemSpriteSheet.ARTIFACT_HORN4;
else if (charge >= 10) image = ItemSpriteSheet.ARTIFACT_HORN3;
else if (charge >= 5) image = ItemSpriteSheet.ARTIFACT_HORN2;
else image = ItemSpriteSheet.ARTIFACT_HORN1;
updateQuickslot();
}
} else if (action.equals(AC_STORE)){
GameScene.selectItem(itemSelector, mode, Messages.get(this, "prompt"));
}
}
@Override
protected ArtifactBuff passiveBuff() {
return new hornRecharge();
}
@Override
public void charge(Hero target) {
if (charge < chargeCap){
partialCharge += 0.25f;
if (partialCharge >= 1){
partialCharge--;
charge++;
if (charge == chargeCap){
GLog.p( Messages.get(HornOfPlenty.class, "full") );
partialCharge = 0;
}
if (charge >= 15) image = ItemSpriteSheet.ARTIFACT_HORN4;
else if (charge >= 10) image = ItemSpriteSheet.ARTIFACT_HORN3;
else if (charge >= 5) image = ItemSpriteSheet.ARTIFACT_HORN2;
updateQuickslot();
}
}
}
@Override
public String desc() {
String desc = super.desc();
if ( isEquipped( Dungeon.hero ) ){
if (!cursed) {
if (level() < levelCap)
desc += "\n\n" +Messages.get(this, "desc_hint");
} else {
desc += "\n\n" +Messages.get(this, "desc_cursed");
}
}
return desc;
}
@Override
public void level(int value) {
super.level(value);
chargeCap = 10 + level();
}
@Override
public Item upgrade() {
super.upgrade();
chargeCap = 10 + level();
return this;
}
public void gainFoodValue( Food food ){
if (level() >= 10) return;
storedFoodEnergy += food.energy;
if (storedFoodEnergy >= Hunger.HUNGRY){
int upgrades = storedFoodEnergy / (int)Hunger.HUNGRY;
upgrades = Math.min(upgrades, 10 - level());
upgrade(upgrades);
storedFoodEnergy -= upgrades * Hunger.HUNGRY;
if (level() == 10){
storedFoodEnergy = 0;
GLog.p( Messages.get(this, "maxlevel") );
} else {
GLog.p( Messages.get(this, "levelup") );
}
} else {
GLog.i( Messages.get(this, "feed") );
}
}
private static final String STORED = "stored";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put( STORED, storedFoodEnergy );
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
storedFoodEnergy = bundle.getInt(STORED);
if (charge >= 15) image = ItemSpriteSheet.ARTIFACT_HORN4;
else if (charge >= 10) image = ItemSpriteSheet.ARTIFACT_HORN3;
else if (charge >= 5) image = ItemSpriteSheet.ARTIFACT_HORN2;
}
public class hornRecharge extends ArtifactBuff{
public void gainCharge(float levelPortion) {
if (cursed) return;
if (charge < chargeCap) {
//generates 0.2x max hunger value every hero level, +0.1x max value per horn level
//to a max of 1.2x max hunger value per hero level
//This means that a standard ration will be recovered in 6.67 hero levels
partialCharge += Hunger.STARVING * levelPortion * (0.2f + (0.1f*level()));
//charge is in increments of 1/10 max hunger value.
while (partialCharge >= Hunger.STARVING/10) {
charge++;
partialCharge -= Hunger.STARVING/10;
if (charge >= 15) image = ItemSpriteSheet.ARTIFACT_HORN4;
else if (charge >= 10) image = ItemSpriteSheet.ARTIFACT_HORN3;
else if (charge >= 5) image = ItemSpriteSheet.ARTIFACT_HORN2;
else image = ItemSpriteSheet.ARTIFACT_HORN1;
if (charge == chargeCap){
GLog.p( Messages.get(HornOfPlenty.class, "full") );
partialCharge = 0;
}
updateQuickslot();
}
} else
partialCharge = 0;
}
}
protected static WndBag.Listener itemSelector = new WndBag.Listener() {
@Override
public void onSelect( Item item ) {
if (item != null && item instanceof Food) {
if (item instanceof Blandfruit && ((Blandfruit) item).potionAttrib == null){
GLog.w( Messages.get(HornOfPlenty.class, "reject") );
} else {
Hero hero = Dungeon.hero;
hero.sprite.operate( hero.pos );
hero.busy();
hero.spend( Food.TIME_TO_EAT );
((HornOfPlenty)curItem).gainFoodValue(((Food)item));
item.detach(hero.belongings.backpack);
}
}
}
};
}
| 7,868 | HornOfPlenty | java | en | java | code | {"qsc_code_num_words": 914, "qsc_code_num_chars": 7868.0, "qsc_code_mean_word_length": 5.93873085, "qsc_code_frac_words_unique": 0.27133479, "qsc_code_frac_chars_top_2grams": 0.02984525, "qsc_code_frac_chars_top_3grams": 0.11901253, "qsc_code_frac_chars_top_4grams": 0.12969786, "qsc_code_frac_chars_dupe_5grams": 0.27652911, "qsc_code_frac_chars_dupe_6grams": 0.21812822, "qsc_code_frac_chars_dupe_7grams": 0.15991157, "qsc_code_frac_chars_dupe_8grams": 0.13890936, "qsc_code_frac_chars_dupe_9grams": 0.13890936, "qsc_code_frac_chars_dupe_10grams": 0.13890936, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01647576, "qsc_code_frac_chars_whitespace": 0.19001017, "qsc_code_size_file_byte": 7868.0, "qsc_code_num_lines": 271.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 29.03321033, "qsc_code_frac_chars_alphabet": 0.83524243, "qsc_code_frac_chars_comments": 0.13993391, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.27225131, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0153687, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05759162, "qsc_codejava_score_lines_no_logic": 0.18324607, "qsc_codejava_frac_words_no_modifier": 0.84615385, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 0.5, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/Artifact.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.KindofMisc;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.utils.Bundle;
import com.watabou.utils.Random;
public class Artifact extends KindofMisc {
protected Buff passiveBuff;
protected Buff activeBuff;
//level is used internally to track upgrades to artifacts, size/logic varies per artifact.
//already inherited from item superclass
//exp is used to count progress towards levels for some artifacts
protected int exp = 0;
//levelCap is the artifact's maximum level
protected int levelCap = 0;
//the current artifact charge
protected int charge = 0;
//the build towards next charge, usually rolls over at 1.
//better to keep charge as an int and use a separate float than casting.
protected float partialCharge = 0;
//the maximum charge, varies per artifact, not all artifacts use this.
protected int chargeCap = 0;
//used by some artifacts to keep track of duration of effects or cooldowns to use.
protected int cooldown = 0;
@Override
public boolean doEquip( final Hero hero ) {
if ((hero.belongings.misc1 != null && hero.belongings.misc1.getClass() == this.getClass())
|| (hero.belongings.misc2 != null && hero.belongings.misc2.getClass() == this.getClass())){
GLog.w( Messages.get(Artifact.class, "cannot_wear_two") );
return false;
} else {
if (super.doEquip( hero )){
identify();
return true;
} else {
return false;
}
}
}
public void activate( Char ch ) {
passiveBuff = passiveBuff();
passiveBuff.attachTo(ch);
}
@Override
public boolean doUnequip( Hero hero, boolean collect, boolean single ) {
if (super.doUnequip( hero, collect, single )) {
passiveBuff.detach();
passiveBuff = null;
if (activeBuff != null){
activeBuff.detach();
activeBuff = null;
}
return true;
} else {
return false;
}
}
@Override
public boolean isUpgradable() {
return false;
}
@Override
public int visiblyUpgraded() {
return levelKnown ? Math.round((level()*10)/(float)levelCap): 0;
}
//transfers upgrades from another artifact, transfer level will equal the displayed level
public void transferUpgrade(int transferLvl) {
upgrade(Math.round((float)(transferLvl*levelCap)/10));
}
@Override
public String info() {
if (cursed && cursedKnown && !isEquipped( Dungeon.hero )) {
return desc() + "\n\n" + Messages.get(Artifact.class, "curse_known");
} else if (!isIdentified() && cursedKnown && !isEquipped( Dungeon.hero)) {
return desc()+ "\n\n" + Messages.get(Artifact.class, "not_cursed");
} else {
return desc();
}
}
@Override
public String status() {
//if the artifact isn't IDed, or is cursed, don't display anything
if (!isIdentified() || cursed){
return null;
}
//display the current cooldown
if (cooldown != 0)
return Messages.format( "%d", cooldown );
//display as percent
if (chargeCap == 100)
return Messages.format( "%d%%", charge );
//display as #/#
if (chargeCap > 0)
return Messages.format( "%d/%d", charge, chargeCap );
//if there's no cap -
//- but there is charge anyway, display that charge
if (charge != 0)
return Messages.format( "%d", charge );
//otherwise, if there's no charge, return null.
return null;
}
@Override
public Item random() {
//always +0
//30% chance to be cursed
if (Random.Float() < 0.3f) {
cursed = true;
}
return this;
}
@Override
public int price() {
int price = 100;
if (level() > 0)
price += 20*visiblyUpgraded();
if (cursed && cursedKnown) {
price /= 2;
}
if (price < 1) {
price = 1;
}
return price;
}
protected ArtifactBuff passiveBuff() {
return null;
}
protected ArtifactBuff activeBuff() {return null; }
public void charge(Hero target){
//do nothing by default;
}
public class ArtifactBuff extends Buff {
public int itemLevel() {
return level();
}
public boolean isCursed() {
return cursed;
}
}
private static final String EXP = "exp";
private static final String CHARGE = "charge";
private static final String PARTIALCHARGE = "partialcharge";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle(bundle);
bundle.put( EXP , exp );
bundle.put( CHARGE , charge );
bundle.put( PARTIALCHARGE , partialCharge );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle(bundle);
exp = bundle.getInt( EXP );
if (chargeCap > 0) charge = Math.min( chargeCap, bundle.getInt( CHARGE ));
else charge = bundle.getInt( CHARGE );
partialCharge = bundle.getFloat( PARTIALCHARGE );
}
}
| 5,912 | Artifact | java | en | java | code | {"qsc_code_num_words": 725, "qsc_code_num_chars": 5912.0, "qsc_code_mean_word_length": 5.69793103, "qsc_code_frac_words_unique": 0.3337931, "qsc_code_frac_chars_top_2grams": 0.02178649, "qsc_code_frac_chars_top_3grams": 0.08278867, "qsc_code_frac_chars_top_4grams": 0.08520939, "qsc_code_frac_chars_dupe_5grams": 0.17017671, "qsc_code_frac_chars_dupe_6grams": 0.04647785, "qsc_code_frac_chars_dupe_7grams": 0.03292181, "qsc_code_frac_chars_dupe_8grams": 0.03292181, "qsc_code_frac_chars_dupe_9grams": 0.03292181, "qsc_code_frac_chars_dupe_10grams": 0.03292181, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01129707, "qsc_code_frac_chars_whitespace": 0.19147497, "qsc_code_size_file_byte": 5912.0, "qsc_code_num_lines": 235.0, "qsc_code_num_chars_line_max": 96.0, "qsc_code_num_chars_line_mean": 25.15744681, "qsc_code_frac_chars_alphabet": 0.85292887, "qsc_code_frac_chars_comments": 0.29228687, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.16197183, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01888145, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.14788732, "qsc_codejava_score_lines_no_logic": 0.33098592, "qsc_codejava_frac_words_no_modifier": 0.73913043, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/TalismanOfForesight.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Awareness;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
public class TalismanOfForesight extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_TALISMAN;
exp = 0;
levelCap = 10;
charge = 0;
partialCharge = 0;
chargeCap = 100;
defaultAction = AC_SCRY;
}
public static final String AC_SCRY = "SCRY";
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (isEquipped( hero ) && charge == chargeCap && !cursed)
actions.add(AC_SCRY);
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute(hero, action);
if (action.equals(AC_SCRY)){
if (!isEquipped(hero)) GLog.i( Messages.get(Artifact.class, "need_to_equip") );
else if (charge != chargeCap) GLog.i( Messages.get(this, "no_charge") );
else {
hero.sprite.operate(hero.pos);
hero.busy();
Sample.INSTANCE.play(Assets.SND_BEACON);
charge = 0;
for (int i = 0; i < Dungeon.level.length(); i++) {
int terr = Dungeon.level.map[i];
if ((Terrain.flags[terr] & Terrain.SECRET) != 0) {
GameScene.updateMap(i);
if (Dungeon.level.heroFOV[i]) {
GameScene.discoverTile(i, terr);
}
}
}
GLog.p( Messages.get(this, "scry") );
updateQuickslot();
Buff.affect(hero, Awareness.class, Awareness.DURATION);
Dungeon.observe();
}
}
}
@Override
protected ArtifactBuff passiveBuff() {
return new Foresight();
}
@Override
public void charge(Hero target) {
if (charge < chargeCap){
charge += 4f;
if (charge >= chargeCap) {
charge = chargeCap;
partialCharge = 0;
GLog.p( Messages.get(Foresight.class, "full_charge") );
}
}
}
@Override
public String desc() {
String desc = super.desc();
if ( isEquipped( Dungeon.hero ) ){
if (!cursed) {
desc += "\n\n" + Messages.get(this, "desc_worn");
} else {
desc += "\n\n" + Messages.get(this, "desc_cursed");
}
}
return desc;
}
private static final String WARN = "warn";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put(WARN, warn);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
warn = bundle.getInt(WARN);
}
private int warn = 0;
public class Foresight extends ArtifactBuff{
@Override
public boolean act() {
spend( TICK );
boolean smthFound = false;
int distance = 3;
int cx = target.pos % Dungeon.level.width();
int cy = target.pos / Dungeon.level.width();
int ax = cx - distance;
if (ax < 0) {
ax = 0;
}
int bx = cx + distance;
if (bx >= Dungeon.level.width()) {
bx = Dungeon.level.width() - 1;
}
int ay = cy - distance;
if (ay < 0) {
ay = 0;
}
int by = cy + distance;
if (by >= Dungeon.level.height()) {
by = Dungeon.level.height() - 1;
}
for (int y = ay; y <= by; y++) {
for (int x = ax, p = ax + y * Dungeon.level.width(); x <= bx; x++, p++) {
if (Dungeon.level.heroFOV[p]
&& Dungeon.level.secret[p]
&& Dungeon.level.map[p] != Terrain.SECRET_DOOR) {
if (Dungeon.level.traps.get(p) != null && Dungeon.level.traps.get(p).canBeSearched) {
smthFound = true;
}
}
}
}
if (smthFound && !cursed){
if (warn == 0){
GLog.w( Messages.get(this, "uneasy") );
if (target instanceof Hero){
((Hero)target).interrupt();
}
}
warn = 3;
} else {
if (warn > 0){
warn --;
}
}
BuffIndicator.refreshHero();
//fully charges in 2000 turns at lvl=0, scaling to 667 turns at lvl = 10.
LockedFloor lock = target.buff(LockedFloor.class);
if (charge < chargeCap && !cursed && (lock == null || lock.regenOn())) {
partialCharge += 0.05+(level()*0.01);
if (partialCharge > 1 && charge < chargeCap) {
partialCharge--;
charge++;
updateQuickslot();
} else if (charge >= chargeCap) {
partialCharge = 0;
GLog.p( Messages.get(this, "full_charge") );
}
}
return true;
}
public void charge(){
charge = Math.min(charge+(2+(level()/3)), chargeCap);
exp++;
if (exp >= 4 && level() < levelCap) {
upgrade();
GLog.p( Messages.get(this, "levelup") );
exp -= 4;
}
updateQuickslot();
}
@Override
public String toString() {
return Messages.get(this, "name");
}
@Override
public String desc() {
return Messages.get(this, "desc");
}
@Override
public int icon() {
if (warn == 0)
return BuffIndicator.NONE;
else
return BuffIndicator.FORESIGHT;
}
}
}
| 6,294 | TalismanOfForesight | java | en | java | code | {"qsc_code_num_words": 752, "qsc_code_num_chars": 6294.0, "qsc_code_mean_word_length": 5.46409574, "qsc_code_frac_words_unique": 0.31515957, "qsc_code_frac_chars_top_2grams": 0.04380628, "qsc_code_frac_chars_top_3grams": 0.1202239, "qsc_code_frac_chars_top_4grams": 0.12849842, "qsc_code_frac_chars_dupe_5grams": 0.15405208, "qsc_code_frac_chars_dupe_6grams": 0.10197128, "qsc_code_frac_chars_dupe_7grams": 0.03407155, "qsc_code_frac_chars_dupe_8grams": 0.02190314, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01289802, "qsc_code_frac_chars_whitespace": 0.21163012, "qsc_code_size_file_byte": 6294.0, "qsc_code_num_lines": 254.0, "qsc_code_num_chars_line_max": 92.0, "qsc_code_num_chars_line_mean": 24.77952756, "qsc_code_frac_chars_alphabet": 0.81519549, "qsc_code_frac_chars_comments": 0.13568478, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.12105263, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01930147, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05789474, "qsc_codejava_score_lines_no_logic": 0.16315789, "qsc_codejava_frac_words_no_modifier": 0.84615385, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/ChaliceOfBlood.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.WandOfLivingEarth;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Earthroot;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
public class ChaliceOfBlood extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_CHALICE1;
levelCap = 10;
}
public static final String AC_PRICK = "PRICK";
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (isEquipped( hero ) && level() < levelCap && !cursed)
actions.add(AC_PRICK);
return actions;
}
@Override
public void execute(Hero hero, String action ) {
super.execute(hero, action);
if (action.equals(AC_PRICK)){
int damage = 3*(level()*level());
if (damage > hero.HP*0.75) {
GameScene.show(
new WndOptions(Messages.titleCase(Messages.get(this, "name")),
Messages.get(this, "prick_warn"),
Messages.get(this, "yes"),
Messages.get(this, "no")) {
@Override
protected void onSelect(int index) {
if (index == 0)
prick(Dungeon.hero);
}
}
);
} else {
prick(hero);
}
}
}
private void prick(Hero hero){
int damage = 3*(level()*level());
Earthroot.Armor armor = hero.buff(Earthroot.Armor.class);
if (armor != null) {
damage = armor.absorb(damage);
}
WandOfLivingEarth.RockArmor rockArmor = hero.buff(WandOfLivingEarth.RockArmor.class);
if (rockArmor != null) {
damage = rockArmor.absorb(damage);
}
damage -= hero.drRoll();
hero.sprite.operate( hero.pos );
hero.busy();
hero.spend(3f);
GLog.w( Messages.get(this, "onprick") );
if (damage <= 0){
damage = 1;
} else {
Sample.INSTANCE.play(Assets.SND_CURSED);
hero.sprite.emitter().burst( ShadowParticle.CURSE, 4+(damage/10) );
}
hero.damage(damage, this);
if (!hero.isAlive()) {
Dungeon.fail( getClass() );
GLog.n( Messages.get(this, "ondeath") );
} else {
upgrade();
}
}
@Override
public Item upgrade() {
if (level() >= 6)
image = ItemSpriteSheet.ARTIFACT_CHALICE3;
else if (level() >= 2)
image = ItemSpriteSheet.ARTIFACT_CHALICE2;
return super.upgrade();
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
if (level() >= 7) image = ItemSpriteSheet.ARTIFACT_CHALICE3;
else if (level() >= 3) image = ItemSpriteSheet.ARTIFACT_CHALICE2;
}
@Override
protected ArtifactBuff passiveBuff() {
return new chaliceRegen();
}
@Override
public void charge(Hero target) {
target.HP = Math.min( target.HT, target.HP + 1 + Dungeon.depth/5);
}
@Override
public String desc() {
String desc = super.desc();
if (isEquipped (Dungeon.hero)){
desc += "\n\n";
if (cursed)
desc += Messages.get(this, "desc_cursed");
else if (level() == 0)
desc += Messages.get(this, "desc_1");
else if (level() < levelCap)
desc += Messages.get(this, "desc_2");
else
desc += Messages.get(this, "desc_3");
}
return desc;
}
public class chaliceRegen extends ArtifactBuff {
}
}
| 4,617 | ChaliceOfBlood | java | en | java | code | {"qsc_code_num_words": 550, "qsc_code_num_chars": 4617.0, "qsc_code_mean_word_length": 5.90727273, "qsc_code_frac_words_unique": 0.36545455, "qsc_code_frac_chars_top_2grams": 0.03878116, "qsc_code_frac_chars_top_3grams": 0.15204678, "qsc_code_frac_chars_top_4grams": 0.16251154, "qsc_code_frac_chars_dupe_5grams": 0.12496153, "qsc_code_frac_chars_dupe_6grams": 0.04616805, "qsc_code_frac_chars_dupe_7grams": 0.02893198, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01201358, "qsc_code_frac_chars_whitespace": 0.1706736, "qsc_code_size_file_byte": 4617.0, "qsc_code_num_lines": 172.0, "qsc_code_num_chars_line_max": 88.0, "qsc_code_num_chars_line_mean": 26.84302326, "qsc_code_frac_chars_alphabet": 0.83651084, "qsc_code_frac_chars_comments": 0.16915746, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.10655738, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01850886, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07377049, "qsc_codejava_score_lines_no_logic": 0.2295082, "qsc_codejava_frac_words_no_modifier": 0.72727273, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 0.5, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/series60/__init__.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"LightBlue - a simple bluetooth library."
# Docstrings for attributes in this module.
_docstrings = {
"finddevices":
"""
Performs a device discovery and returns the found devices as a list of
(address, name, class-of-device) tuples. Raises BluetoothError if an error
occurs.
Arguments:
- getnames=True: True if device names should be retrieved during
discovery. If false, None will be returned instead of the device
name.
- length=10: the number of seconds to spend discovering devices
(this argument has no effect on Python for Series 60)
Do not invoke a new discovery before a previous discovery has finished.
Also, to minimise interference with other wireless and bluetooth traffic,
and to conserve battery power on the local device, discoveries should not
be invoked too frequently (an interval of at least 20 seconds is
recommended).
""",
"findservices":
"""
Performs a service discovery and returns the found services as a list of
(device-address, service-port, service-name) tuples. Raises BluetoothError
if an error occurs.
Arguments:
- addr=None: a device address, to search only for services on a
specific device
- name=None: a service name string, to search only for a service with a
specific name
- servicetype=None: can be RFCOMM or OBEX to search only for RFCOMM or
OBEX-type services. (OBEX services are not returned from an RFCOMM
search)
If more than one criteria is specified, this returns services that match
all criteria.
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.
""",
"finddevicename":
"""
Returns the name of the device with the given bluetooth address.
finddevicename(gethostaddr()) returns the local device name.
Arguments:
- address: the address of the device to look up
- usecache=True: if True, the device name will be fetched from a local
cache if possible. If False, or if the device name is not in the
cache, the remote device will be contacted to request its name.
Raise BluetoothError if the name cannot be retrieved.
""",
"gethostaddr":
"""
Returns the address of the local bluetooth device.
Raise BluetoothError if the local device is not available.
""",
"gethostclass":
"""
Returns the class of device of the local bluetooth device.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Raise BluetoothError if the local device is not available.
""",
"socket":
"""
socket(proto=RFCOMM) -> socket object
Returns a new socket object.
Arguments:
- proto=RFCOMM: the type of socket to be created - either L2CAP or
RFCOMM.
Note that L2CAP sockets are not available on Python For Series 60, and
only L2CAP client sockets are supported on Mac OS X and Linux (i.e. you can
connect() the socket but not bind(), accept(), etc.).
""",
"advertise":
"""
Starts advertising a service with the given name, using the given server
socket. Raises BluetoothError if the service cannot be advertised.
Arguments:
- name: name of the service to be advertised
- sock: the socket object that will serve this service. The socket must
be already bound to a channel. If a RFCOMM service is being
advertised, the socket should also be listening.
- servicetype: the type of service to advertise - either RFCOMM or
OBEX. (L2CAP services are not currently supported.)
(If the servicetype is RFCOMM, the service will be advertised with the
Serial Port Profile; if the servicetype is OBEX, the service will be
advertised with the OBEX Object Push Profile.)
""",
"stopadvertise":
"""
Stops advertising the service on the given socket. Raises BluetoothError if
no service is advertised on the socket.
This will error if the given socket is already closed.
""",
"selectdevice":
"""
Displays a GUI which allows the end user to select a device from a list of
discovered devices.
Returns the selected device as an (address, name, class-of-device) tuple.
Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
""",
"selectservice":
"""
Displays a GUI which allows the end user to select a service from a list of
discovered devices and their services.
Returns the selected service as a (device-address, service-port, service-
name) tuple. Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.
"""
}
# import implementation modules
from _lightblue import *
from _lightbluecommon import *
import obex # plus submodule
# set docstrings
import _lightblue
localattrs = locals()
for attr in _lightblue.__all__:
try:
localattrs[attr].__doc__ = _docstrings[attr]
except KeyError:
pass
del attr, localattrs
| 6,362 | __init__ | py | en | python | code | {"qsc_code_num_words": 877, "qsc_code_num_chars": 6362.0, "qsc_code_mean_word_length": 4.99657925, "qsc_code_frac_words_unique": 0.32041049, "qsc_code_frac_chars_top_2grams": 0.01141031, "qsc_code_frac_chars_top_3grams": 0.02053857, "qsc_code_frac_chars_top_4grams": 0.02327704, "qsc_code_frac_chars_dupe_5grams": 0.26289366, "qsc_code_frac_chars_dupe_6grams": 0.21497033, "qsc_code_frac_chars_dupe_7grams": 0.17343679, "qsc_code_frac_chars_dupe_8grams": 0.15837517, "qsc_code_frac_chars_dupe_9grams": 0.13555454, "qsc_code_frac_chars_dupe_10grams": 0.13555454, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00527649, "qsc_code_frac_chars_whitespace": 0.25526564, "qsc_code_size_file_byte": 6362.0, "qsc_code_num_lines": 172.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 36.98837209, "qsc_code_frac_chars_alphabet": 0.91958632, "qsc_code_frac_chars_comments": 0.12951902, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.27191413, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.03030303, "qsc_codepython_frac_lines_import": 0.12121212, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.12121212, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRetribution.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Weakness;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.audio.Sample;
public class ScrollOfRetribution extends Scroll {
{
initials = 4;
}
@Override
public void doRead() {
GameScene.flash( 0xFFFFFF );
//scales from 0x to 1x power, maxing at ~10% HP
float hpPercent = (curUser.HT - curUser.HP)/(float)(curUser.HT);
float power = Math.min( 4f, 4.45f*hpPercent);
Sample.INSTANCE.play( Assets.SND_BLAST );
Invisibility.dispel();
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (Dungeon.level.heroFOV[mob.pos]) {
//deals 10%HT, plus 0-90%HP based on scaling
mob.damage(Math.round(mob.HT/10f + (mob.HP * power * 0.225f)), this);
if (mob.isAlive()) {
Buff.prolong(mob, Blindness.class, Math.round(6 + power));
}
}
}
Buff.prolong(curUser, Weakness.class, Weakness.DURATION/2f);
Buff.prolong(curUser, Blindness.class, Math.round(6 + power));
Dungeon.observe();
setKnown();
readAnimation();
}
@Override
public void empoweredRead() {
GameScene.flash( 0xFFFFFF );
Sample.INSTANCE.play( Assets.SND_BLAST );
Invisibility.dispel();
//scales from 3x to 5x power, maxing at ~20% HP
float hpPercent = (curUser.HT - curUser.HP)/(float)(curUser.HT);
float power = Math.min( 5f, 3f + 2.5f*hpPercent);
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (Dungeon.level.heroFOV[mob.pos]) {
mob.damage(Math.round(mob.HP * power/5f), this);
}
}
setKnown();
readAnimation();
}
@Override
public int price() {
return isKnown() ? 40 * quantity : super.price();
}
}
| 2,949 | ScrollOfRetribution | java | en | java | code | {"qsc_code_num_words": 385, "qsc_code_num_chars": 2949.0, "qsc_code_mean_word_length": 5.49090909, "qsc_code_frac_words_unique": 0.44415584, "qsc_code_frac_chars_top_2grams": 0.07237465, "qsc_code_frac_chars_top_3grams": 0.16177862, "qsc_code_frac_chars_top_4grams": 0.16650899, "qsc_code_frac_chars_dupe_5grams": 0.38505203, "qsc_code_frac_chars_dupe_6grams": 0.32923368, "qsc_code_frac_chars_dupe_7grams": 0.17123936, "qsc_code_frac_chars_dupe_8grams": 0.17123936, "qsc_code_frac_chars_dupe_9grams": 0.12393567, "qsc_code_frac_chars_dupe_10grams": 0.12393567, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02235772, "qsc_code_frac_chars_whitespace": 0.16581892, "qsc_code_size_file_byte": 2949.0, "qsc_code_num_lines": 97.0, "qsc_code_num_chars_line_max": 75.0, "qsc_code_num_chars_line_mean": 30.40206186, "qsc_code_frac_chars_alphabet": 0.83699187, "qsc_code_frac_chars_comments": 0.31163106, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.34545455, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00788177, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07272727, "qsc_codejava_score_lines_no_logic": 0.25454545, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTransmutation.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Challenges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.exotic.ExoticScroll;
import com.shatteredpixel.shatteredpixeldungeon.items.stones.Runestone;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
import com.shatteredpixel.shatteredpixeldungeon.items.Generator;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.Artifact;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.AlchemicalCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.Potion;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.brews.Brew;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.elixirs.Elixir;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic.ExoticPotion;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MeleeWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.MissileWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart;
import com.shatteredpixel.shatteredpixeldungeon.journal.Catalog;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Plant;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.utils.Random;
import com.watabou.utils.Reflection;
public class ScrollOfTransmutation extends InventoryScroll {
{
initials = 10;
mode = WndBag.Mode.TRANMSUTABLE;
bones = true;
}
public static boolean canTransmute(Item item){
return item instanceof MeleeWeapon ||
(item instanceof MissileWeapon && !(item instanceof Dart)) ||
(item instanceof Potion && !(item instanceof Elixir || item instanceof Brew || item instanceof AlchemicalCatalyst)) ||
item instanceof Scroll ||
item instanceof Ring ||
item instanceof Wand ||
item instanceof Plant.Seed ||
item instanceof Runestone ||
item instanceof Artifact;
}
@Override
protected void onItemSelected(Item item) {
Item result;
if (item instanceof MagesStaff) {
result = changeStaff( (MagesStaff)item );
} else if (item instanceof MeleeWeapon || item instanceof MissileWeapon) {
result = changeWeapon( (Weapon)item );
} else if (item instanceof Scroll) {
result = changeScroll( (Scroll)item );
} else if (item instanceof Potion) {
result = changePotion( (Potion)item );
} else if (item instanceof Ring) {
result = changeRing( (Ring)item );
} else if (item instanceof Wand) {
result = changeWand( (Wand)item );
} else if (item instanceof Plant.Seed) {
result = changeSeed((Plant.Seed) item);
} else if (item instanceof Runestone) {
result = changeStone((Runestone) item);
} else if (item instanceof Artifact) {
result = changeArtifact( (Artifact)item );
} else {
result = null;
}
if (result == null){
//This shouldn't ever trigger
GLog.n( Messages.get(this, "nothing") );
curItem.collect( curUser.belongings.backpack );
} else {
if (item.isEquipped(Dungeon.hero)){
item.cursed = false; //to allow it to be unequipped
((EquipableItem)item).doUnequip(Dungeon.hero, false);
((EquipableItem)result).doEquip(Dungeon.hero);
} else {
item.detach(Dungeon.hero.belongings.backpack);
if (!result.collect()){
Dungeon.level.drop(result, curUser.pos).sprite.drop();
}
}
if (result.isIdentified()){
Catalog.setSeen(result.getClass());
}
//TODO visuals
GLog.p( Messages.get(this, "morph") );
}
}
private MagesStaff changeStaff( MagesStaff staff ){
Class<?extends Wand> wandClass = staff.wandClass();
if (wandClass == null){
return null;
} else {
Wand n;
do {
n = (Wand) Generator.random(Generator.Category.WAND);
} while (Challenges.isItemBlocked(n) || n.getClass() == wandClass);
n.level(0);
n.identify();
staff.imbueWand(n, null);
}
return staff;
}
private Weapon changeWeapon( Weapon w ) {
Weapon n;
Generator.Category c;
if (w instanceof MeleeWeapon) {
c = Generator.wepTiers[((MeleeWeapon)w).tier - 1];
} else {
c = Generator.misTiers[((MissileWeapon)w).tier - 1];
}
do {
n = (Weapon) Reflection.newInstance(c.classes[Random.chances(c.probs)]);
} while (Challenges.isItemBlocked(n) || n.getClass() == w.getClass());
int level = w.level();
if (w.curseInfusionBonus) level--;
if (level > 0) {
n.upgrade( level );
} else if (level < 0) {
n.degrade( -level );
}
n.enchantment = w.enchantment;
n.curseInfusionBonus = w.curseInfusionBonus;
n.levelKnown = w.levelKnown;
n.cursedKnown = w.cursedKnown;
n.cursed = w.cursed;
n.augment = w.augment;
return n;
}
private Ring changeRing( Ring r ) {
Ring n;
do {
n = (Ring)Generator.random( Generator.Category.RING );
} while (Challenges.isItemBlocked(n) || n.getClass() == r.getClass());
n.level(0);
int level = r.level();
if (level > 0) {
n.upgrade( level );
} else if (level < 0) {
n.degrade( -level );
}
n.levelKnown = r.levelKnown;
n.cursedKnown = r.cursedKnown;
n.cursed = r.cursed;
return n;
}
private Artifact changeArtifact( Artifact a ) {
Artifact n = Generator.randomArtifact();
if (n != null && !Challenges.isItemBlocked(n)){
n.cursedKnown = a.cursedKnown;
n.cursed = a.cursed;
n.levelKnown = a.levelKnown;
n.transferUpgrade(a.visiblyUpgraded());
return n;
}
return null;
}
private Wand changeWand( Wand w ) {
Wand n;
do {
n = (Wand)Generator.random( Generator.Category.WAND );
} while ( Challenges.isItemBlocked(n) || n.getClass() == w.getClass());
n.level( 0 );
int level = w.level();
if (w.curseInfusionBonus) level--;
n.upgrade( level );
n.levelKnown = w.levelKnown;
n.cursedKnown = w.cursedKnown;
n.cursed = w.cursed;
n.curseInfusionBonus = w.curseInfusionBonus;
return n;
}
private Plant.Seed changeSeed( Plant.Seed s ) {
Plant.Seed n;
do {
n = (Plant.Seed)Generator.random( Generator.Category.SEED );
} while (n.getClass() == s.getClass());
return n;
}
private Runestone changeStone( Runestone r ) {
Runestone n;
do {
n = (Runestone) Generator.random( Generator.Category.STONE );
} while (n.getClass() == r.getClass());
return n;
}
private Scroll changeScroll( Scroll s ) {
if (s instanceof ExoticScroll) {
return Reflection.newInstance(ExoticScroll.exoToReg.get(s.getClass()));
} else {
return Reflection.newInstance(ExoticScroll.regToExo.get(s.getClass()));
}
}
private Potion changePotion( Potion p ) {
if (p instanceof ExoticPotion) {
return Reflection.newInstance(ExoticPotion.exoToReg.get(p.getClass()));
} else {
return Reflection.newInstance(ExoticPotion.regToExo.get(p.getClass()));
}
}
@Override
public void empoweredRead() {
//does nothing, this shouldn't happen
}
@Override
public int price() {
return isKnown() ? 50 * quantity : super.price();
}
}
| 8,317 | ScrollOfTransmutation | java | en | java | code | {"qsc_code_num_words": 950, "qsc_code_num_chars": 8317.0, "qsc_code_mean_word_length": 6.24842105, "qsc_code_frac_words_unique": 0.24842105, "qsc_code_frac_chars_top_2grams": 0.04093666, "qsc_code_frac_chars_top_3grams": 0.16644205, "qsc_code_frac_chars_top_4grams": 0.18530997, "qsc_code_frac_chars_dupe_5grams": 0.34855121, "qsc_code_frac_chars_dupe_6grams": 0.22540431, "qsc_code_frac_chars_dupe_7grams": 0.1305593, "qsc_code_frac_chars_dupe_8grams": 0.08911725, "qsc_code_frac_chars_dupe_9grams": 0.06704852, "qsc_code_frac_chars_dupe_10grams": 0.06704852, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00433088, "qsc_code_frac_chars_whitespace": 0.16712757, "qsc_code_size_file_byte": 8317.0, "qsc_code_num_lines": 278.0, "qsc_code_num_chars_line_max": 123.0, "qsc_code_num_chars_line_mean": 29.91726619, "qsc_code_frac_chars_alphabet": 0.85260575, "qsc_code_frac_chars_comments": 0.10700974, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.25837321, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00161573, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00359712, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06220096, "qsc_codejava_score_lines_no_logic": 0.26794258, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRecharging.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.EnergyParticle;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
public class ScrollOfRecharging extends Scroll {
public static final float BUFF_DURATION = 30f;
{
initials = 6;
}
@Override
public void doRead() {
Buff.affect(curUser, Recharging.class, BUFF_DURATION);
charge(curUser);
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
GLog.i( Messages.get(this, "surge") );
SpellSprite.show( curUser, SpellSprite.CHARGE );
setKnown();
readAnimation();
}
@Override
public void empoweredRead() {
doRead();
Buff.append(curUser, Recharging.class, BUFF_DURATION/3f);
}
public static void charge( Hero hero ) {
hero.sprite.centerEmitter().burst( EnergyParticle.FACTORY, 15 );
}
@Override
public int price() {
return isKnown() ? 30 * quantity : super.price();
}
}
| 2,262 | ScrollOfRecharging | java | en | java | code | {"qsc_code_num_words": 275, "qsc_code_num_chars": 2262.0, "qsc_code_mean_word_length": 6.30909091, "qsc_code_frac_words_unique": 0.53090909, "qsc_code_frac_chars_top_2grams": 0.09798271, "qsc_code_frac_chars_top_3grams": 0.21902017, "qsc_code_frac_chars_top_4grams": 0.22824207, "qsc_code_frac_chars_dupe_5grams": 0.26916427, "qsc_code_frac_chars_dupe_6grams": 0.12737752, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01284027, "qsc_code_frac_chars_whitespace": 0.13925729, "qsc_code_size_file_byte": 2262.0, "qsc_code_num_lines": 72.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 31.41666667, "qsc_code_frac_chars_alphabet": 0.87827427, "qsc_code_frac_chars_comments": 0.34526967, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.075, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0033761, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.125, "qsc_codejava_score_lines_no_logic": 0.4, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | examples/LightAquaBlue/SimpleOBEXClient/SimpleOBEXClient.m | #import "SimpleOBEXClient.h"
#import <LightAquaBlue/LightAquaBlue.h>
#import <IOBluetooth/IOBluetoothUtilities.h>
#import <IOBluetoothUI/objc/IOBluetoothServiceBrowserController.h>
@implementation SimpleOBEXClient
- (void)awakeFromNib
{
[[connectButton window] center];
[[connectButton window] performSelector:@selector(makeFirstResponder:)
withObject:connectButton
afterDelay:0.0];
}
- (void)log:(NSString *)text
{
[logTextView insertText:text];
[logTextView insertText:@"\n"];
}
- (NSNumber *)getSizeOfFile:(NSString *)filePath
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:filePath traverseLink:YES];
if (fileAttributes != nil)
return [fileAttributes objectForKey:NSFileSize];
return nil;
}
- (IBAction)findService:(id)sender
{
IOBluetoothServiceBrowserController *browser =
[IOBluetoothServiceBrowserController serviceBrowserController:0];
if ([browser runModal] == kIOBluetoothUISuccess) {
IOBluetoothSDPServiceRecord *service = [[browser getResults] objectAtIndex:0];
[addressField setStringValue:[[service getDevice] getAddressString]];
BluetoothRFCOMMChannelID channelID;
if ([service getRFCOMMChannelID:&channelID] == kIOReturnSuccess)
[channelField setIntValue:channelID];
}
}
- (IBAction)connectOrDisconnect:(id)sender
{
if (!mClient) {
if (![BBLocalDevice isPoweredOn]) {
[self log:@"Bluetooth device is not available!"];
return;
}
NSString *deviceAddressString = [addressField stringValue];
BluetoothDeviceAddress deviceAddress;
if (IOBluetoothNSStringToDeviceAddress(deviceAddressString, &deviceAddress) != kIOReturnSuccess) {
[self log:[NSString stringWithFormat:@"%@ is not a valid Bluetooth device address!",
deviceAddressString]];
return;
}
// Create a BBBluetoothOBEXClient that will connect to the OBEX
// server on the specified address and channel.
mClient = [[BBBluetoothOBEXClient alloc] initWithRemoteDeviceAddress:&deviceAddress
channelID:[channelField intValue]
delegate:self];
}
if (![mClient isConnected]) {
[self log:[NSString stringWithFormat:@"Connecting to %@ on channel %d...",
[addressField stringValue], [channelField intValue]]];
// Send a Connect request to start the OBEX session.
// You must send a Connect request before you send any other types of
// requests.
OBEXError status = [mClient sendConnectRequestWithHeaders:nil];
if (status == kOBEXSuccess) {
[self log:@"Sent 'Connect' request, waiting for response..."];
[connectionProgress startAnimation:nil];
[connectButton setEnabled:NO];
} else {
[self log:[NSString stringWithFormat:@"Connection error! (%d)", status]];
}
} else {
[self log:@"Disconnecting..."];
// Send a Disconnect requst to close the OBEX session.
OBEXError status = [mClient sendDisconnectRequestWithHeaders:nil];
if (status == kOBEXSuccess) {
[self log:@"Sent 'Disconnect' request, waiting for response..."];
[connectionProgress startAnimation:nil];
[connectButton setEnabled:NO];
} else {
[self log:[NSString stringWithFormat:@"Disconnection error! (%d)", status]];
}
}
}
- (IBAction)chooseFile:(id)sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
if ([openPanel runModalForTypes:nil] == NSOKButton)
[filePathField setStringValue:[[openPanel filenames] objectAtIndex:0]];
}
- (IBAction)sendFile:(id)sender
{
NSString *filePath = [filePathField stringValue];
// Open a stream that will read from the local file. It doesn't have to be
// retained because the client will retain it for the duration of the
// request.
NSInputStream *fileInputStream = [NSInputStream inputStreamWithFileAtPath:filePath];
[fileInputStream open]; // must be opened
// Attach some request headers that tell the server the name and size of
// the file that we are sending.
BBMutableOBEXHeaderSet *headerSet = [BBMutableOBEXHeaderSet headerSet];
[headerSet setValueForNameHeader:[filePath lastPathComponent]];
NSNumber *fileSize = [self getSizeOfFile:filePath];
if (fileSize) {
[headerSet setValueForLengthHeader:[fileSize unsignedIntValue]];
[transferProgress setIndeterminate:NO];
[transferProgress setMaxValue:[fileSize unsignedIntValue]];
[self log:[NSString stringWithFormat:@"Sending file of size: %d",
[fileSize unsignedIntValue]]];
} else {
[transferProgress setIndeterminate:YES];
}
[self log:[NSString stringWithFormat:@"Sending Put request with file <%@>",
filePath]];
// send the request
OBEXError status = [mClient sendPutRequestWithHeaders:headerSet
readFromStream:fileInputStream];
if (status == kOBEXSuccess) {
[self log:@"Sending file..."];
[sendButton setEnabled:NO];
[cancelButton setEnabled:YES];
[transferProgress startAnimation:nil];
} else {
[self log:[NSString stringWithFormat:@"Put request error! (%d)", status]];
}
}
- (IBAction)cancelFileTransfer:(id)sender
{
[self log:@"Attempting to cancel transfer..."];
[mClient abortCurrentRequest];
}
#pragma mark -
#pragma mark BBBluetoothOBEXClient delegate methods
// The following delegate methods allow the BBBluetoothOBEXClient to notify
// you when an OBEX event has occurred. You must wait for a notification
// that a request has finished before start the next request! For example,
// if you send a Connect request, you must wait for
// client:didFinishConnectRequestWithError:response: to
// be called until you send another request. Otherwise, the OBEX server on the
// other end cannot process your requests correctly.
- (void)client:(BBBluetoothOBEXClient *)client
didFinishConnectRequestWithError:(OBEXError)error
response:(BBOBEXResponse *)response
{
if (error == kOBEXSuccess) {
if ([response responseCode] == kOBEXResponseCodeSuccessWithFinalBit) {
[self log:@"Connected."];
[connectButton setTitle:@"Disconnect"];
} else {
[self log:[NSString stringWithFormat:@"Connect request refused (%@)",
[response responseCodeDescription]]];
}
} else {
[self log:[NSString stringWithFormat:@"Connect error! (%d)", error]];
}
[connectButton setEnabled:YES];
[connectionProgress stopAnimation:nil];
}
- (void)client:(BBBluetoothOBEXClient *)client
didFinishDisconnectRequestWithError:(OBEXError)error
response:(BBOBEXResponse *)response
{
if (error == kOBEXSuccess) {
if ([response responseCode] == kOBEXResponseCodeSuccessWithFinalBit) {
[self log:@"Disconnected."];
} else {
[self log:[NSString stringWithFormat:@"Disconnect request refused (%@)",
[response responseCodeDescription]]];
}
} else {
[self log:[NSString stringWithFormat:@"Disconnect error! (%d)", error]];
}
// close the baseband connection to the remote device
[[[client RFCOMMChannel] getDevice] closeConnection];
[connectButton setTitle:@"Connect"];
[connectButton setEnabled:YES];
[connectionProgress stopAnimation:nil];
}
- (void)client:(BBBluetoothOBEXClient *)client
didFinishPutRequestForStream:(NSInputStream *)inputStream
error:(OBEXError)error
response:(BBOBEXResponse *)response
{
if (error == kOBEXSuccess) {
if ([response responseCode] == kOBEXResponseCodeSuccessWithFinalBit) {
[self log:@"File sent successfully."];
} else {
[self log:[NSString stringWithFormat:@"Put request refused (%@)",
[response responseCodeDescription]]];
}
} else {
[self log:[NSString stringWithFormat:@"Put error! (%d)", error]];
}
[inputStream close];
[transferProgress stopAnimation:nil];
[sendButton setEnabled:YES];
[cancelButton setEnabled:NO];
}
- (void)client:(BBBluetoothOBEXClient *)client
didSendDataOfLength:(unsigned)length
{
[self log:[NSString stringWithFormat:@"Sent another %d bytes...", length]];
[transferProgress incrementBy:length];
}
- (void)client:(BBBluetoothOBEXClient *)session
didAbortRequestWithStream:(NSStream *)stream
error:(OBEXError)error
response:(BBOBEXResponse *)response
{
if (error == kOBEXSuccess) {
if ([response responseCode] == kOBEXResponseCodeSuccessWithFinalBit) {
[self log:@"File transfer cancelled."];
} else {
[self log:[NSString stringWithFormat:@"Abort request refused (%@)",
[response responseCodeDescription]]];
}
} else {
[self log:[NSString stringWithFormat:@"Abort error! (%d)", error]];
}
[stream close];
[transferProgress stopAnimation:nil];
[transferProgress setDoubleValue:0];
[sendButton setEnabled:YES];
[cancelButton setEnabled:NO];
}
- (void)dealloc
{
[mClient release];
[super dealloc];
}
@end
| 9,732 | SimpleOBEXClient | m | en | limbo | code | {"qsc_code_num_words": 788, "qsc_code_num_chars": 9732.0, "qsc_code_mean_word_length": 7.98604061, "qsc_code_frac_words_unique": 0.31852792, "qsc_code_frac_chars_top_2grams": 0.02892102, "qsc_code_frac_chars_top_3grams": 0.03813761, "qsc_code_frac_chars_top_4grams": 0.07881773, "qsc_code_frac_chars_dupe_5grams": 0.29048149, "qsc_code_frac_chars_dupe_6grams": 0.26839345, "qsc_code_frac_chars_dupe_7grams": 0.24423963, "qsc_code_frac_chars_dupe_8grams": 0.20403623, "qsc_code_frac_chars_dupe_9grams": 0.20403623, "qsc_code_frac_chars_dupe_10grams": 0.15318608, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00081878, "qsc_code_frac_chars_whitespace": 0.24702014, "qsc_code_size_file_byte": 9732.0, "qsc_code_num_lines": 271.0, "qsc_code_num_chars_line_max": 107.0, "qsc_code_num_chars_line_mean": 35.91143911, "qsc_code_frac_chars_alphabet": 0.85794214, "qsc_code_frac_chars_comments": 0.02548294, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.24, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.07307043, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
0-1-0/lightblue-0.4 | examples/LightAquaBlue/SimpleOBEXServer/SimpleOBEXServer.m | //
// SimpleOBEXServer.m
//
// This shows how BBBluetoothOBEXServer can be used to run a simple OBEX
// server that allows clients to send and retrieve files.
//
// To receive files through this server, you'll need to get the remote device
// to specifically send them to the channel that's being used by this OBEX
// service -- that is, the channel number that's displayed when this example
// prints the "Listening for connections on channel X" message.
//
// If you can't specify a channel when sending files from the remote device --
// for example, the Mac OS X "Send File..." Bluetooth utility only lets you
// select a device, and not the channel -- this probably means the device is
// just sending it to the first appropriate OBEX service that it finds. So if
// you switch off all other OBEX services, e.g. the Mac OS X built-in OBEX
// services, this demo's OBEX service should automatically receive the files.
//
// To switch off the built-in OBEX services on Mac OS 10.5 go to
// System Preferences -> Sharing and uncheck the "Bluetooth Sharing" checkbox.
// This disables the built-in OBEX Object Push and OBEX File Transfer services.
//
// On Mac OS 10.4, go to System Preferences -> Bluetooth and click the
// "Sharing" tab. Uncheck the "On" checkboxes for the "Bluetooth File Transfer"
// and "Bluetooth File Exchange" services.
//
// On Mac OS 10.3, go to System Preferences -> Bluetooth, and go to the "File
// Exchange" tab. For "When receiving items", select "Refuse all", and also
// uncheck "Allow other devices to browse files on this computer".
//
// If the device that's sending files is a Mac, then you can can specify the
// channel ID programmatically: the included SimpleOBEXClient example, as well
// as Apple's OBEXSample (in /Developer/Examples/Bluetooth) and the
// IOBluetooth OBEXFileTransferServices class all let you connect to a
// specific channel when connecting to an OBEX service.
//
#import "SimpleOBEXServer.h"
#include <LightAquaBlue/LightAquaBlue.h>
#include <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
#include <IOBluetooth/IOBluetoothUtilities.h>
@implementation SimpleOBEXServer
- (id)init
{
self = [super init];
mOBEXServers = [[NSMutableDictionary alloc] initWithCapacity:0];
mConnections = [[NSMutableArray alloc] initWithCapacity:0];
mServiceRecordHandle = 0;
return self;
}
- (void)awakeFromNib
{
[serverDirectoryField setStringValue:[[NSFileManager defaultManager] currentDirectoryPath]];
[[logView window] center];
//[BBBluetoothOBEXServer setDebug:YES];
}
- (void)log:(NSString *)text
{
[logView insertText:text];
[logView insertText:@"\n"];
}
- (NSNumber *)getSizeOfFile:(NSString *)filePath
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:filePath traverseLink:YES];
if (fileAttributes != nil)
return [fileAttributes objectForKey:NSFileSize];
return nil;
}
//
// Starts or stops the server.
//
- (IBAction)startOrStopServer:(id)sender
{
if (!mChannelNotification) {
[self log:@"Starting server..."];
// Advertise an OBEX service so that other devices can find us when
// they look for available services on our local Bluetooth device.
BluetoothRFCOMMChannelID serverChannelID;
BluetoothSDPServiceRecordHandle serviceRecordHandle;
IOReturn result =
[BBServiceAdvertiser addRFCOMMServiceDictionary:[BBServiceAdvertiser objectPushProfileDictionary]
withName:[serviceNameField stringValue]
UUID:nil
channelID:&serverChannelID
serviceRecordHandle:&serviceRecordHandle];
if (result != kOBEXSuccess) {
[self log:[NSString stringWithFormat:@"Error advertising service (%d)", result]];
return;
}
// keep the service record handle so the service can be unregistered
// later
mServiceRecordHandle = serviceRecordHandle;
// Tell IOBluetoothRFCOMMChannel to call channelOpened:channel:
// when a client connects on <serverChannelID>, which is the channel
// ID on which the OBEX service was advertised.
mChannelNotification =
[IOBluetoothRFCOMMChannel registerForChannelOpenNotifications:self
selector:@selector(channelOpened:channel:)
withChannelID:serverChannelID
direction:kIOBluetoothUserNotificationChannelDirectionIncoming];
[mChannelNotification retain];
[self log:[NSString stringWithFormat:@"Listening for connections on channel %d",
serverChannelID]];
[startButton setTitle:@"Stop server"];
} else {
[self log:@"Stopping server..."];
// Stop listening for RFCOMM client connections, and remove the
// service that was previously advertised.
[mChannelNotification unregister];
[mChannelNotification release];
mChannelNotification = nil;
[BBServiceAdvertiser removeService:mServiceRecordHandle];
mServiceRecordHandle = 0;
[self log:@"Server stopped."];
[startButton setTitle:@"Start server"];
}
}
//
// Called by IOBluetoothRFCOMMChannel when a RFCOMM client has connected.
// The provided <channel> is the newly opened RFCOMM channel.
//
- (void)channelOpened:(IOBluetoothUserNotification *)notification
channel:(IOBluetoothRFCOMMChannel *)channel
{
NSString *remoteAddress = [[channel getDevice] getAddressString];
[mConnectionsController addObject:remoteAddress];
[self log:[NSString stringWithFormat:@"=> Client connected from %@",
remoteAddress]];
// create a BBBluetoothOBEXServer that will run on this new RFCOMM channel
BBBluetoothOBEXServer *server =
[BBBluetoothOBEXServer serverWithIncomingRFCOMMChannel:channel
delegate:self];
// Tell IOBluetoothRFCOMMChannel to call channelClosed:channel: when this
// channel is closed, and add the new server to a dictionary so the object
// can be retained until the channel is closed.
[channel registerForChannelCloseNotification:self selector:@selector(channelClosed:channel:)];
[mOBEXServers setObject:server forKey:channel];
// start the server
[server run];
}
//
// Called by IOBluetoothRFCOMMChannel when a RFCOMM channel is closed (i.e when
// a client has disconnected).
//
- (void)channelClosed:(IOBluetoothUserNotification *)notification
channel:(IOBluetoothRFCOMMChannel *)channel
{
NSString *remoteAddress = [[channel getDevice] getAddressString];
[mConnectionsController removeObject:remoteAddress];
[self log:[NSString stringWithFormat:@"=> Connection closed from %@",
remoteAddress]];
// the BBBluetoothOBEXServer running on this particular channel can now
// be released
[mOBEXServers removeObjectForKey:channel];
}
#pragma mark -
#pragma mark BBBluetoothOBEXServer delegate methods
// The following delegate methods are called by the BBBluetoothOBEXServer object
// when an OBEX server event occurs. This is where you can actually respond and
// perform operations when a client connects, sends files, etc.
//
// For the sake of simplicity, the delegate methods relating to SetPath and
// Put-Delete requests have not been implemented here, which means that this
// server won't support these particular requests.
//
// Called when an error occurs on the server.
//
- (void)server:(BBBluetoothOBEXServer *)server
errorOccurred:(OBEXError)error
description:(NSString *)description
{
[self log:@"----------"];
[self log:[NSString stringWithFormat:@"Server error: %@ (%d)", description,
error]];
[self log:@"----------"];
}
//
// Called when a Connect request is received.
//
- (BOOL)server:(BBBluetoothOBEXServer *)server
shouldHandleConnectRequest:(BBOBEXHeaderSet *)requestHeaders
{
[self log:@"Got CONNECT request"];
return YES;
}
//
// Called when a Connect request is finished.
//
- (void)serverDidHandleConnectRequest:(BBBluetoothOBEXServer *)server
{
[self log:@"Finished handling CONNECT request"];
}
//
// Called when a Disconnect request is received.
//
- (BOOL)server:(BBBluetoothOBEXServer *)server
shouldHandleDisconnectRequest:(BBOBEXHeaderSet *)requestHeaders
{
[self log:@"Got DISCONNECT request"];
return YES;
}
//
// Called when a Disconnect request is finished.
//
- (void)serverDidHandleDisconnectRequest:(BBBluetoothOBEXServer *)server
{
[self log:@"Finished handling DISCONNECT request"];
}
//
// Called when a Put request is received.
//
- (NSOutputStream *)server:(BBBluetoothOBEXServer *)server
shouldHandlePutRequest:(BBOBEXHeaderSet *)requestHeaders
{
// The client should have sent some information about the file, such as
// its name and length.
NSString *incomingFileName = [requestHeaders valueForNameHeader];
if (!incomingFileName)
incomingFileName = @"unnamed_file";
[self log:[NSString stringWithFormat:@"Got PUT request, client wants to send file '%@'",
incomingFileName]];
// See if the client told us how big the file is.
// kOBEXHeaderIDLength and other header IDs are defined in OBEX.h in
// IOBluetooth.framework.
if ([requestHeaders containsValueForHeader:kOBEXHeaderIDLength]) {
[self log:[NSString stringWithFormat:@"Incoming file is %d bytes",
[requestHeaders valueForLengthHeader]]];
}
// IOBluetoothGetUniqueFileNameAndPath() is a useful function in
// <IOBluetooth/IOBluetoothUtilities.h> for creating a unique file name.
NSString *filePath = IOBluetoothGetUniqueFileNameAndPath(incomingFileName,
[serverDirectoryField stringValue]);
[self log:[NSString stringWithFormat:@"File will be saved to <%@>", filePath]];
// Now open a stream that will write to the file. It doesn't have to be
// retained because the server will retain it for the duration of the
// request.
NSOutputStream *stream = [NSOutputStream outputStreamToFileAtPath:filePath
append:NO];
[stream open]; // must open stream or else it can't be used!
return stream;
}
//
// Called each time data is received during a Put request.
//
- (BOOL)server:(BBBluetoothOBEXServer *)server
didReceiveDataOfLength:(unsigned)length
isLastPacket:(BOOL)isLastPacket
{
[self log:[NSString stringWithFormat:@"Got another %d bytes", length]];
return YES;
}
//
// Called when a Put request is finished.
//
- (void)server:(BBBluetoothOBEXServer *)server
didHandlePutRequestForStream:(NSOutputStream *)outputStream
requestWasAborted:(BOOL)aborted
{
[self log:@"Finished PUT request"];
[outputStream close];
}
//
// Called when a Get request is received.
//
- (NSInputStream *)server:(BBBluetoothOBEXServer *)server
shouldHandleGetRequest:(BBOBEXHeaderSet *)requestHeaders
{
// See what file the client wants to retrieve.
NSString *fileName = [requestHeaders valueForNameHeader];
if (!fileName) {
[self log:@"Got GET request but client didn't send a filename, refusing request..."];
return NO;
}
[self log:[NSString stringWithFormat:@"Got GET request, client wants to get file '%@'",
fileName]];
NSString *filePath = [[serverDirectoryField stringValue] stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
[self log:[NSString stringWithFormat:@"Cannot find file <%@>, refusing request...",
filePath]];
// You can use setResponseCodeForCurrentRequest: to set a more specific
// response; otherwise if you return NO, the default response will
// be 'Forbidden'.
[server setResponseCodeForCurrentRequest:kOBEXResponseCodeNotFoundWithFinalBit];
return NO;
}
// Use the response headers to inform the client of the file's size so it
// knows how much data is expected.
NSNumber *fileSize = [self getSizeOfFile:filePath];
if (fileSize) {
BBMutableOBEXHeaderSet *responseHeaders = [BBMutableOBEXHeaderSet headerSet];
[responseHeaders setValueForLengthHeader:[fileSize unsignedIntValue]];
[server addResponseHeadersForCurrentRequest:responseHeaders];
}
// Now open a stream that will read from the file. It doesn't have to be
// retained because the server will retain it for the duration of the
// request.
NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:filePath];
[stream open]; // must open stream or it can't be used!
return stream;
}
//
// Called each time data is sent for a Get request.
//
- (void)server:(BBBluetoothOBEXServer *)server
didSendDataOfLength:(unsigned)length
{
[self log:[NSString stringWithFormat:@"Sent another %d bytes", length]];
}
//
// Called when a Get request is finished.
//
- (void)server:(BBBluetoothOBEXServer *)server
didHandleGetRequestForStream:(NSInputStream *)inputStream
requestWasAborted:(BOOL)aborted
{
[self log:@"Finished GET request"];
[inputStream close];
}
- (void)dealloc
{
if (mServiceRecordHandle != 0)
[BBServiceAdvertiser removeService:mServiceRecordHandle];
[mChannelNotification release];
[mOBEXServers release];
[super dealloc];
}
@end
| 13,941 | SimpleOBEXServer | m | en | limbo | code | {"qsc_code_num_words": 1384, "qsc_code_num_chars": 13941.0, "qsc_code_mean_word_length": 6.88511561, "qsc_code_frac_words_unique": 0.30274566, "qsc_code_frac_chars_top_2grams": 0.01763039, "qsc_code_frac_chars_top_3grams": 0.01888971, "qsc_code_frac_chars_top_4grams": 0.03903872, "qsc_code_frac_chars_dupe_5grams": 0.18952671, "qsc_code_frac_chars_dupe_6grams": 0.14838913, "qsc_code_frac_chars_dupe_7grams": 0.0816455, "qsc_code_frac_chars_dupe_8grams": 0.05897786, "qsc_code_frac_chars_dupe_9grams": 0.05897786, "qsc_code_frac_chars_dupe_10grams": 0.05897786, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00129582, "qsc_code_frac_chars_whitespace": 0.22501973, "qsc_code_size_file_byte": 13941.0, "qsc_code_num_lines": 378.0, "qsc_code_num_chars_line_max": 129.0, "qsc_code_num_chars_line_mean": 36.88095238, "qsc_code_frac_chars_alphabet": 0.88069234, "qsc_code_frac_chars_comments": 0.01707195, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.22429907, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.00311526, "qsc_code_frac_chars_string_length": 0.06589798, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfUpgrade.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.Ring;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
public class ScrollOfUpgrade extends InventoryScroll {
{
initials = 11;
mode = WndBag.Mode.UPGRADEABLE;
}
@Override
protected void onItemSelected( Item item ) {
upgrade( curUser );
//logic for telling the user when item properties change from upgrades
//...yes this is rather messy
if (item instanceof Weapon){
Weapon w = (Weapon) item;
boolean wasCursed = w.cursed;
boolean hadCursedEnchant = w.hasCurseEnchant();
boolean hadGoodEnchant = w.hasGoodEnchant();
w.upgrade();
if (w.cursedKnown && hadCursedEnchant && !w.hasCurseEnchant()){
removeCurse( Dungeon.hero );
} else if (w.cursedKnown && wasCursed && !w.cursed){
weakenCurse( Dungeon.hero );
}
if (hadGoodEnchant && !w.hasGoodEnchant()){
GLog.w( Messages.get(Weapon.class, "incompatible") );
}
} else if (item instanceof Armor){
Armor a = (Armor) item;
boolean wasCursed = a.cursed;
boolean hadCursedGlyph = a.hasCurseGlyph();
boolean hadGoodGlyph = a.hasGoodGlyph();
a.upgrade();
if (a.cursedKnown && hadCursedGlyph && !a.hasCurseGlyph()){
removeCurse( Dungeon.hero );
} else if (a.cursedKnown && wasCursed && !a.cursed){
weakenCurse( Dungeon.hero );
}
if (hadGoodGlyph && !a.hasGoodGlyph()){
GLog.w( Messages.get(Armor.class, "incompatible") );
}
} else if (item instanceof Wand || item instanceof Ring) {
boolean wasCursed = item.cursed;
item.upgrade();
if (wasCursed && !item.cursed){
removeCurse( Dungeon.hero );
}
} else {
item.upgrade();
}
Badges.validateItemLevelAquired( item );
Statistics.upgradesUsed++;
Badges.validateMageUnlock();
}
public static void upgrade( Hero hero ) {
hero.sprite.emitter().start( Speck.factory( Speck.UP ), 0.2f, 3 );
}
public static void weakenCurse( Hero hero ){
GLog.p( Messages.get(ScrollOfUpgrade.class, "weaken_curse") );
hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 5 );
}
public static void removeCurse( Hero hero ){
GLog.p( Messages.get(ScrollOfUpgrade.class, "remove_curse") );
hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 );
}
@Override
public void empoweredRead() {
//does nothing for now, this should never happen.
}
@Override
public int price() {
return isKnown() ? 50 * quantity : super.price();
}
}
| 4,068 | ScrollOfUpgrade | java | en | java | code | {"qsc_code_num_words": 470, "qsc_code_num_chars": 4068.0, "qsc_code_mean_word_length": 6.34680851, "qsc_code_frac_words_unique": 0.38297872, "qsc_code_frac_chars_top_2grams": 0.08548441, "qsc_code_frac_chars_top_3grams": 0.1910828, "qsc_code_frac_chars_top_4grams": 0.20650352, "qsc_code_frac_chars_dupe_5grams": 0.26852162, "qsc_code_frac_chars_dupe_6grams": 0.10459269, "qsc_code_frac_chars_dupe_7grams": 0.0610124, "qsc_code_frac_chars_dupe_8grams": 0.0610124, "qsc_code_frac_chars_dupe_9grams": 0.0315119, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00961258, "qsc_code_frac_chars_whitespace": 0.15609636, "qsc_code_size_file_byte": 4068.0, "qsc_code_num_lines": 127.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 32.03149606, "qsc_code_frac_chars_alphabet": 0.85930673, "qsc_code_frac_chars_comments": 0.22836775, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.12048193, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01529149, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08433735, "qsc_codejava_score_lines_no_logic": 0.26506024, "qsc_codejava_frac_words_no_modifier": 0.75, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/InventoryScroll.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.audio.Sample;
public abstract class InventoryScroll extends Scroll {
protected String inventoryTitle = Messages.get(this, "inv_title");
protected WndBag.Mode mode = WndBag.Mode.ALL;
@Override
public void doRead() {
if (!isKnown()) {
setKnown();
identifiedByUse = true;
} else {
identifiedByUse = false;
}
GameScene.selectItem( itemSelector, mode, inventoryTitle );
}
private void confirmCancelation() {
GameScene.show( new WndOptions( Messages.titleCase(name()), Messages.get(this, "warning"),
Messages.get(this, "yes"), Messages.get(this, "no") ) {
@Override
protected void onSelect( int index ) {
switch (index) {
case 0:
curUser.spendAndNext( TIME_TO_READ );
identifiedByUse = false;
break;
case 1:
GameScene.selectItem( itemSelector, mode, inventoryTitle );
break;
}
}
public void onBackPressed() {}
} );
}
protected abstract void onItemSelected( Item item );
protected static boolean identifiedByUse = false;
protected static WndBag.Listener itemSelector = new WndBag.Listener() {
@Override
public void onSelect( Item item ) {
//FIXME this safety check shouldn't be necessary
//it would be better to eliminate the curItem static variable.
if (!(curItem instanceof InventoryScroll)){
return;
}
if (item != null) {
((InventoryScroll)curItem).onItemSelected( item );
((InventoryScroll)curItem).readAnimation();
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
} else if (identifiedByUse && !((Scroll)curItem).anonymous) {
((InventoryScroll)curItem).confirmCancelation();
} else if (!((Scroll)curItem).anonymous) {
curItem.collect( curUser.belongings.backpack );
}
}
};
}
| 3,122 | InventoryScroll | java | en | java | code | {"qsc_code_num_words": 349, "qsc_code_num_chars": 3122.0, "qsc_code_mean_word_length": 6.45272206, "qsc_code_frac_words_unique": 0.49856734, "qsc_code_frac_chars_top_2grams": 0.06039076, "qsc_code_frac_chars_top_3grams": 0.13499112, "qsc_code_frac_chars_top_4grams": 0.13676732, "qsc_code_frac_chars_dupe_5grams": 0.12522202, "qsc_code_frac_chars_dupe_6grams": 0.02486679, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00742187, "qsc_code_frac_chars_whitespace": 0.18001281, "qsc_code_size_file_byte": 3122.0, "qsc_code_num_lines": 101.0, "qsc_code_num_chars_line_max": 93.0, "qsc_code_num_chars_line_mean": 30.91089109, "qsc_code_frac_chars_alphabet": 0.87226563, "qsc_code_frac_chars_comments": 0.28539398, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.14754098, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00941282, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00990099, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08196721, "qsc_codejava_score_lines_no_logic": 0.24590164, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CloakOfShadows.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Preparation;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroSubClass;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.tweeners.AlphaTweener;
import com.watabou.utils.Bundle;
import java.util.ArrayList;
public class CloakOfShadows extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_CLOAK;
exp = 0;
levelCap = 10;
charge = Math.min(level()+3, 10);
partialCharge = 0;
chargeCap = Math.min(level()+3, 10);
defaultAction = AC_STEALTH;
unique = true;
bones = false;
}
private boolean stealthed = false;
public static final String AC_STEALTH = "STEALTH";
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (isEquipped( hero ) && !cursed && (charge > 0 || stealthed))
actions.add(AC_STEALTH);
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute(hero, action);
if (action.equals( AC_STEALTH )) {
if (!stealthed){
if (!isEquipped(hero)) GLog.i( Messages.get(Artifact.class, "need_to_equip") );
else if (cursed) GLog.i( Messages.get(this, "cursed") );
else if (charge <= 0) GLog.i( Messages.get(this, "no_charge") );
else {
stealthed = true;
hero.spend( 1f );
hero.busy();
Sample.INSTANCE.play(Assets.SND_MELD);
activeBuff = activeBuff();
activeBuff.attachTo(hero);
if (hero.sprite.parent != null) {
hero.sprite.parent.add(new AlphaTweener(hero.sprite, 0.4f, 0.4f));
} else {
hero.sprite.alpha(0.4f);
}
hero.sprite.operate(hero.pos);
}
} else {
stealthed = false;
activeBuff.detach();
activeBuff = null;
hero.spend( 1f );
hero.sprite.operate( hero.pos );
}
}
}
@Override
public void activate(Char ch){
super.activate(ch);
if (stealthed){
activeBuff = activeBuff();
activeBuff.attachTo(ch);
}
}
@Override
public boolean doUnequip(Hero hero, boolean collect, boolean single) {
if (super.doUnequip(hero, collect, single)){
stealthed = false;
return true;
} else
return false;
}
@Override
protected ArtifactBuff passiveBuff() {
return new cloakRecharge();
}
@Override
protected ArtifactBuff activeBuff( ) {
return new cloakStealth();
}
@Override
public void charge(Hero target) {
if (charge < chargeCap) {
partialCharge += 0.25f;
if (partialCharge >= 1){
partialCharge--;
charge++;
updateQuickslot();
}
}
}
@Override
public Item upgrade() {
chargeCap = Math.min(chargeCap + 1, 10);
return super.upgrade();
}
private static final String STEALTHED = "stealthed";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle(bundle);
bundle.put( STEALTHED, stealthed );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle(bundle);
stealthed = bundle.getBoolean( STEALTHED );
}
@Override
public int price() {
return 0;
}
public class cloakRecharge extends ArtifactBuff{
@Override
public boolean act() {
if (charge < chargeCap) {
LockedFloor lock = target.buff(LockedFloor.class);
if (!stealthed && (lock == null || lock.regenOn())) {
float missing = (chargeCap - charge);
if (level() > 7) missing += 5*(level() - 7)/3f;
float turnsToCharge = (45 - missing);
partialCharge += (1f / turnsToCharge);
}
if (partialCharge >= 1) {
charge++;
partialCharge -= 1;
if (charge == chargeCap){
partialCharge = 0;
}
}
} else
partialCharge = 0;
if (cooldown > 0)
cooldown --;
updateQuickslot();
spend( TICK );
return true;
}
}
public class cloakStealth extends ArtifactBuff{
{
type = buffType.POSITIVE;
}
int turnsToCost = 0;
@Override
public int icon() {
return BuffIndicator.INVISIBLE;
}
@Override
public boolean attachTo( Char target ) {
if (super.attachTo( target )) {
target.invisible++;
if (target instanceof Hero && ((Hero) target).subClass == HeroSubClass.ASSASSIN){
Buff.affect(target, Preparation.class);
}
return true;
} else {
return false;
}
}
@Override
public boolean act(){
turnsToCost--;
if (turnsToCost <= 0){
charge--;
if (charge < 0) {
charge = 0;
detach();
GLog.w(Messages.get(this, "no_charge"));
((Hero) target).interrupt();
} else {
//target hero level is 1 + 2*cloak level
int lvlDiffFromTarget = ((Hero) target).lvl - (1+level()*2);
//plus an extra one for each level after 6
if (level() >= 7){
lvlDiffFromTarget -= level()-6;
}
if (lvlDiffFromTarget >= 0){
exp += Math.round(10f * Math.pow(1.1f, lvlDiffFromTarget));
} else {
exp += Math.round(10f * Math.pow(0.75f, -lvlDiffFromTarget));
}
if (exp >= (level() + 1) * 50 && level() < levelCap) {
upgrade();
exp -= level() * 50;
GLog.p(Messages.get(this, "levelup"));
}
turnsToCost = 5;
}
updateQuickslot();
}
spend( TICK );
return true;
}
public void dispel(){
updateQuickslot();
detach();
}
@Override
public void fx(boolean on) {
if (on) target.sprite.add( CharSprite.State.INVISIBLE );
else if (target.invisible == 0) target.sprite.remove( CharSprite.State.INVISIBLE );
}
@Override
public String toString() {
return Messages.get(this, "name");
}
@Override
public String desc() {
return Messages.get(this, "desc");
}
@Override
public void detach() {
if (target.invisible > 0)
target.invisible--;
stealthed = false;
updateQuickslot();
super.detach();
}
private static final String TURNSTOCOST = "turnsToCost";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put( TURNSTOCOST , turnsToCost);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
turnsToCost = bundle.getInt( TURNSTOCOST );
}
}
}
| 7,672 | CloakOfShadows | java | en | java | code | {"qsc_code_num_words": 849, "qsc_code_num_chars": 7672.0, "qsc_code_mean_word_length": 6.04122497, "qsc_code_frac_words_unique": 0.29328622, "qsc_code_frac_chars_top_2grams": 0.05186196, "qsc_code_frac_chars_top_3grams": 0.10372392, "qsc_code_frac_chars_top_4grams": 0.11152271, "qsc_code_frac_chars_dupe_5grams": 0.26086957, "qsc_code_frac_chars_dupe_6grams": 0.16007019, "qsc_code_frac_chars_dupe_7grams": 0.05888087, "qsc_code_frac_chars_dupe_8grams": 0.05888087, "qsc_code_frac_chars_dupe_9grams": 0.05888087, "qsc_code_frac_chars_dupe_10grams": 0.02963541, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01416571, "qsc_code_frac_chars_whitespace": 0.20868092, "qsc_code_size_file_byte": 7672.0, "qsc_code_num_lines": 322.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 23.82608696, "qsc_code_frac_chars_alphabet": 0.8306704, "qsc_code_frac_chars_comments": 0.11248697, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.29218107, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01160229, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08641975, "qsc_codejava_score_lines_no_logic": 0.20164609, "qsc_codejava_frac_words_no_modifier": 0.875, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 0.33333333, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | doc/lightblue-Socket_objects.html | <html>
<head>
<title>Socket objects</title>
<link rel='stylesheet' href='shortdoc.css' />
</head>
<body>
<h2 class='moduletitle'>package <span class='modulename'><a href='index.html'>lightblue</a>:</span></h2>
<div class='class'>
<h3 class='classtitle'>Socket objects</h3>
<pre class='doc'> A Bluetooth socket object has the same interface as a socket object from
the Python standard library <socket> module. It also uses the same
exceptions, raising socket.error for general errors and socket.timeout for
timeout errors.
Note that L2CAP sockets are not available on Python For Series 60, and
only L2CAP client sockets are supported on Mac OS X and Linux.
A simple client socket example:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>from</span> lightblue <span class='keyword'>import</span> *
<span class="interpreter">>>></span> s = socket() <span class='comment'># or socket(L2CAP) to create an L2CAP socket</span>
<span class="interpreter">>>></span> s.connect((<span class='string'>"00:12:2c:45:8a:7b"</span>, <span class='number'>5</span>))
<span class="interpreter">>>></span> s.send(<span class='string'>"hello"</span>)
<span class='number'>5</span>
<span class="interpreter">>>></span> s.close()</code></pre>
A simple server socket example:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>from</span> lightblue <span class='keyword'>import</span> *
<span class="interpreter">>>></span> s = socket()
<span class="interpreter">>>></span> s.bind((<span class='string'>""</span>, <span class='number'>0</span>))
<span class="interpreter">>>></span> s.listen(<span class='number'>1</span>)
<span class="interpreter">>>></span> advertise(<span class='string'>"My RFCOMM Service"</span>, s, RFCOMM)
<span class="interpreter">>>></span> conn, addr = s.accept()
<span class="interpreter">>>></span> <span class='keyword'>print</span> <span class='string'>"Connected by"</span>, addr
Connected by (<span class='string'>'00:0D:93:19:C8:68'</span>, <span class='number'>5</span>)
<span class="interpreter">>>></span> conn.recv(<span class='number'>1024</span>)
<span class='string'>"hello"</span>
<span class="interpreter">>>></span> conn.close()
<span class="interpreter">>>></span> s.close()</code></pre></pre>
<div id='methods' class='section'>
<h2 class='sectiontitle'>Methods</h2>
<div id='functionlinks'>
<ul>
<li><a href='#accept'><strong>accept</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#bind'><strong>bind</strong>(<span class='sig'>address</span>)
</a></li>
<li><a href='#close'><strong>close</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#connect'><strong>connect</strong>(<span class='sig'>address</span>)
</a></li>
<li><a href='#connect_ex'><strong>connect_ex</strong>(<span class='sig'>address</span>)
</a></li>
<li><a href='#dup'><strong>dup</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#fileno'><strong>fileno</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#getpeername'><strong>getpeername</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#getsockname'><strong>getsockname</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#getsockopt'><strong>getsockopt</strong>(<span class='sig'>level, option[, bufsize]</span>)
</a></li>
<li><a href='#gettimeout'><strong>gettimeout</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#listen'><strong>listen</strong>(<span class='sig'>backlog</span>)
</a></li>
<li><a href='#makefile'><strong>makefile</strong>(<span class='sig'>[mode[, bufsize]]</span>)
</a></li>
<li><a href='#recv'><strong>recv</strong>(<span class='sig'>bufsize[, flags]</span>)
</a></li>
<li><a href='#recvfrom'><strong>recvfrom</strong>(<span class='sig'>bufsize[, flags]</span>)
</a></li>
<li><a href='#send'><strong>send</strong>(<span class='sig'>data[, flags]</span>)
</a></li>
<li><a href='#sendall'><strong>sendall</strong>(<span class='sig'>data[, flags]</span>)
</a></li>
<li><a href='#sendto'><strong>sendto</strong>(<span class='sig'>data[, flags], address</span>)
</a></li>
<li><a href='#setblocking'><strong>setblocking</strong>(<span class='sig'>flag</span>)
</a></li>
<li><a href='#setsockopt'><strong>setsockopt</strong>(<span class='sig'>level, option, value</span>)
</a></li>
<li><a href='#settimeout'><strong>settimeout</strong>(<span class='sig'>timeout</span>)
</a></li>
<li><a href='#shutdown'><strong>shutdown</strong>(<span class='sig'>how</span>)
</a></li>
</ul>
</div>
<a name='accept'></a><h4 class='methodtitle'>accept(<span class='sig'></span>)
</h4>
<pre class='doc'>
accept() -> (socket object, address info)
Wait for an incoming connection. Return a new socket representing the
connection, and the address of the client. For RFCOMM sockets, the address
info is a pair (hostaddr, channel).
The socket must be bound and listening before calling this method.</pre>
<a name='bind'></a><h4 class='methodtitle'>bind(<span class='sig'>address</span>)
</h4>
<pre class='doc'>
bind(address)
Bind the socket to a local address. For RFCOMM sockets, the address is a
pair (host, channel); the host must refer to the local host.
A port value of 0 binds the socket to a dynamically assigned port.
(Note that on Mac OS X, the port value must always be 0.)
The socket must not already be bound.</pre>
<a name='close'></a><h4 class='methodtitle'>close(<span class='sig'></span>)
</h4>
<pre class='doc'>
close()
Close the socket. It cannot be used after this call.</pre>
<a name='connect'></a><h4 class='methodtitle'>connect(<span class='sig'>address</span>)
</h4>
<pre class='doc'>
connect(address)
Connect the socket to a remote address. The address should be a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
The socket must not be already connected.</pre>
<a name='connect_ex'></a><h4 class='methodtitle'>connect_ex(<span class='sig'>address</span>)
</h4>
<pre class='doc'>
connect_ex(address) -> errno
This is like connect(address), but returns an error code instead of raising
an exception when an error occurs.</pre>
<a name='dup'></a><h4 class='methodtitle'>dup(<span class='sig'></span>)
</h4>
<pre class='doc'>
dup() -> socket object
Returns a new socket object connected to the same system resource.</pre>
<a name='fileno'></a><h4 class='methodtitle'>fileno(<span class='sig'></span>)
</h4>
<pre class='doc'>
fileno() -> integer
Return the integer file descriptor of the socket.
Raises NotImplementedError on Mac OS X and Python For Series 60.</pre>
<a name='getpeername'></a><h4 class='methodtitle'>getpeername(<span class='sig'></span>)
</h4>
<pre class='doc'>
getpeername() -> address info
Return the address of the remote endpoint. The address info is a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
If the socket has not been connected, socket.error will be raised.</pre>
<a name='getsockname'></a><h4 class='methodtitle'>getsockname(<span class='sig'></span>)
</h4>
<pre class='doc'>
getsockname() -> address info
Return the address of the local endpoint. The address info is a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
If the socket has not been connected nor bound, this returns the tuple
("00:00:00:00:00:00", 0).</pre>
<a name='getsockopt'></a><h4 class='methodtitle'>getsockopt(<span class='sig'>level, option[, bufsize]</span>)
</h4>
<pre class='doc'>
getsockopt(level, option[, bufsize]) -> value
Get a socket option. See the Unix manual for level and option.
If a nonzero buffersize argument is given, the return value is a
string of that length; otherwise it is an integer.
Currently support for socket options are platform independent -- i.e.
depends on the underlying Series 60 or BlueZ socket options support.
The Mac OS X implementation currently does not support any options at
all and automatically raises socket.error.</pre>
<a name='gettimeout'></a><h4 class='methodtitle'>gettimeout(<span class='sig'></span>)
</h4>
<pre class='doc'>
gettimeout() -> timeout
Returns the timeout in floating seconds associated with socket
operations. A timeout of None indicates that timeouts on socket
operations are disabled.
Currently not supported on Python For Series 60 implementation, which
will always return None.</pre>
<a name='listen'></a><h4 class='methodtitle'>listen(<span class='sig'>backlog</span>)
</h4>
<pre class='doc'>
listen(backlog)
Enable a server to accept connections. The backlog argument must be at
least 1; it specifies the number of unaccepted connection that the system
will allow before refusing new connections.
The socket must not be already listening.
Currently not implemented on Mac OS X.</pre>
<a name='makefile'></a><h4 class='methodtitle'>makefile(<span class='sig'>[mode[, bufsize]]</span>)
</h4>
<pre class='doc'>
makefile([mode[, bufsize]]) -> file object
Returns a regular file object corresponding to the socket. The mode
and bufsize arguments are as for the built-in open() function.</pre>
<a name='recv'></a><h4 class='methodtitle'>recv(<span class='sig'>bufsize[, flags]</span>)
</h4>
<pre class='doc'>
recv(bufsize[, flags]) -> data
Receive up to bufsize bytes from the socket. For the optional flags
argument, see the Unix manual. When no data is available, block until
at least one byte is available or until the remote end is closed. When
the remote end is closed and all data is read, return the empty string.
Currently the flags argument has no effect on Mac OS X.</pre>
<a name='recvfrom'></a><h4 class='methodtitle'>recvfrom(<span class='sig'>bufsize[, flags]</span>)
</h4>
<pre class='doc'>
recvfrom(bufsize[, flags]) -> (data, address info)
Like recv(buffersize, flags) but also return the sender's address info.</pre>
<a name='send'></a><h4 class='methodtitle'>send(<span class='sig'>data[, flags]</span>)
</h4>
<pre class='doc'>
send(data[, flags]) -> count
Send a data string to the socket. For the optional flags
argument, see the Unix manual. Return the number of bytes
sent.
The socket must be connected to a remote socket.
Currently the flags argument has no effect on Mac OS X.</pre>
<a name='sendall'></a><h4 class='methodtitle'>sendall(<span class='sig'>data[, flags]</span>)
</h4>
<pre class='doc'>
sendall(data[, flags])
Send a data string to the socket. For the optional flags
argument, see the Unix manual. This calls send() repeatedly
until all data is sent. If an error occurs, it's impossible
to tell how much data has been sent.</pre>
<a name='sendto'></a><h4 class='methodtitle'>sendto(<span class='sig'>data[, flags], address</span>)
</h4>
<pre class='doc'>
sendto(data[, flags], address) -> count
Like send(data, flags) but allows specifying the destination address.
For RFCOMM sockets, the address is a pair (hostaddr, channel).</pre>
<a name='setblocking'></a><h4 class='methodtitle'>setblocking(<span class='sig'>flag</span>)
</h4>
<pre class='doc'>
setblocking(flag)
Set the socket to blocking (flag is true) or non-blocking (false).
setblocking(True) is equivalent to settimeout(None);
setblocking(False) is equivalent to settimeout(0.0).
Initially a socket is in blocking mode. In non-blocking mode, if a
socket operation cannot be performed immediately, socket.error is raised.</pre>
<a name='setsockopt'></a><h4 class='methodtitle'>setsockopt(<span class='sig'>level, option, value</span>)
</h4>
<pre class='doc'>
setsockopt(level, option, value)
Set a socket option. See the Unix manual for level and option.
The value argument can either be an integer or a string.
Currently support for socket options are platform independent -- i.e.
depends on the underlying Series 60 or BlueZ socket options support.
The Mac OS X implementation currently does not support any options at
all and automatically raise socket.error.</pre>
<a name='settimeout'></a><h4 class='methodtitle'>settimeout(<span class='sig'>timeout</span>)
</h4>
<pre class='doc'>
settimeout(timeout)
Set a timeout on socket operations. 'timeout' can be a float,
giving in seconds, or None. Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
If a timeout is set, the connect, accept, send and receive operations will
raise socket.timeout if a timeout occurs.
Raises NotImplementedError on Python For Series 60.</pre>
<a name='shutdown'></a><h4 class='methodtitle'>shutdown(<span class='sig'>how</span>)
</h4>
<pre class='doc'>
shutdown(how)
Shut down the reading side of the socket (flag == socket.SHUT_RD), the
writing side of the socket (flag == socket.SHUT_WR), or both ends
(flag == socket.SHUT_RDWR).</pre>
</div>
</div>
</body></html> | 13,668 | lightblue-Socket_objects | html | en | html | code | {"qsc_code_num_words": 2034, "qsc_code_num_chars": 13668.0, "qsc_code_mean_word_length": 4.46656834, "qsc_code_frac_words_unique": 0.1553589, "qsc_code_frac_chars_top_2grams": 0.07826087, "qsc_code_frac_chars_top_3grams": 0.05811778, "qsc_code_frac_chars_top_4grams": 0.04358833, "qsc_code_frac_chars_dupe_5grams": 0.4526142, "qsc_code_frac_chars_dupe_6grams": 0.39823886, "qsc_code_frac_chars_dupe_7grams": 0.3760044, "qsc_code_frac_chars_dupe_8grams": 0.33032471, "qsc_code_frac_chars_dupe_9grams": 0.29058888, "qsc_code_frac_chars_dupe_10grams": 0.26549257, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01022191, "qsc_code_frac_chars_whitespace": 0.16256951, "qsc_code_size_file_byte": 13668.0, "qsc_code_num_lines": 329.0, "qsc_code_num_chars_line_max": 162.0, "qsc_code_num_chars_line_mean": 41.54407295, "qsc_code_frac_chars_alphabet": 0.78350515, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.33333333, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.09481308, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codehtml_cate_ast": 1.0, "qsc_codehtml_frac_words_text": 0.59642962, "qsc_codehtml_num_chars_text": 8152.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_codehtml_cate_ast": 0, "qsc_codehtml_frac_words_text": 0, "qsc_codehtml_num_chars_text": 0} |
0-1-0/lightblue-0.4 | doc/index.html | <html>
<head>
<title>package lightblue</title>
<link rel='stylesheet' href='shortdoc.css' />
</head>
<body>
<div class='module'>
<h2 class='moduletitle'>package <span class='modulename'>lightblue</span></h2>
<pre class='doc'>LightBlue - a simple bluetooth library.</pre><div id='submodules' class='section'>
<h2 class='sectiontitle'>Sub-modules</h2>
<a href='lightblue.obex.html'><h2 class='moduletitle'>module <span class='modulename'>lightblue.obex</span></h2>
</a><div class='doc'>Provides an OBEX client class and convenience functions for sending and
receiving files over OBEX.</div>
</div>
<div id='classes' class='section'>
<h2 class='sectiontitle'>Classes & Types</h2>
<div class='class'>
<a href='lightblue-Socket_objects.html'><h3 class='classtitle'>Socket objects</h3></a>
<div class='doc'>A Bluetooth socket object has the same interface as a socket object from
the Python standard library <socket> module.</div>
</div>
<div class='class'>
<a href='lightblue-BluetoothError.html'><h3 class='classtitle'>exception <span class='classname'>BluetoothError</span> <span class='superclasstitle'>(<tt>exceptions.IOError</tt>)</span></h3>
</a>
<div class='doc'>Generic exception raised for Bluetooth errors.</div>
</div>
</div>
<div id='functions' class='section'>
<h2 class='sectiontitle'>Functions</h2>
<div id='functionlinks'>
<ul>
<li><a href='#finddevices'><strong>finddevices</strong>(<span class='sig'>getnames=True, length=10</span>)
</a></li>
<li><a href='#findservices'><strong>findservices</strong>(<span class='sig'>addr=None, name=None, servicetype=None</span>)
</a></li>
<li><a href='#finddevicename'><strong>finddevicename</strong>(<span class='sig'>address, usecache=True</span>)
</a></li>
<li><a href='#selectdevice'><strong>selectdevice</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#selectservice'><strong>selectservice</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#gethostaddr'><strong>gethostaddr</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#gethostclass'><strong>gethostclass</strong>(<span class='sig'></span>)
</a></li>
<li><a href='#socket'><strong>socket</strong>(<span class='sig'>proto=RFCOMM</span>)
</a></li>
<li><a href='#advertise'><strong>advertise</strong>(<span class='sig'>name, sock, servicetype</span>)
</a></li>
<li><a href='#stopadvertise'><strong>stopadvertise</strong>(<span class='sig'>sock</span>)
</a></li>
<li><a href='#splitclass'><strong>splitclass</strong>(<span class='sig'>classofdevice</span>)
</a></li>
</ul>
</div>
<a name='finddevices'></a><h4 class='functitle'>finddevices(<span class='sig'>getnames=True, length=10</span>)
</h4>
<pre class='doc'>
Performs a device discovery and returns the found devices as a list of
(address, name, class-of-device) tuples. Raises BluetoothError if an error
occurs.
Arguments:
- getnames=True: True if device names should be retrieved during
discovery. If false, None will be returned instead of the device
name.
- length=10: the number of seconds to spend discovering devices
(this argument has no effect on Python for Series 60)
Do not invoke a new discovery before a previous discovery has finished.
Also, to minimise interference with other wireless and bluetooth traffic,
and to conserve battery power on the local device, discoveries should not
be invoked too frequently (an interval of at least 20 seconds is
recommended).</pre>
<a name='findservices'></a><h4 class='functitle'>findservices(<span class='sig'>addr=None, name=None, servicetype=None</span>)
</h4>
<pre class='doc'>
Performs a service discovery and returns the found services as a list of
(device-address, service-port, service-name) tuples. Raises BluetoothError
if an error occurs.
Arguments:
- addr=None: a device address, to search only for services on a
specific device
- name=None: a service name string, to search only for a service with a
specific name
- servicetype=None: can be RFCOMM or OBEX to search only for RFCOMM or
OBEX-type services. (OBEX services are not returned from an RFCOMM
search)
If more than one criteria is specified, this returns services that match
all criteria.
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.</pre>
<a name='finddevicename'></a><h4 class='functitle'>finddevicename(<span class='sig'>address, usecache=True</span>)
</h4>
<pre class='doc'>
Returns the name of the device with the given bluetooth address.
finddevicename(gethostaddr()) returns the local device name.
Arguments:
- address: the address of the device to look up
- usecache=True: if True, the device name will be fetched from a local
cache if possible. If False, or if the device name is not in the
cache, the remote device will be contacted to request its name.
Raise BluetoothError if the name cannot be retrieved.</pre>
<a name='selectdevice'></a><h4 class='functitle'>selectdevice(<span class='sig'></span>)
</h4>
<pre class='doc'>
Displays a GUI which allows the end user to select a device from a list of
discovered devices.
Returns the selected device as an (address, name, class-of-device) tuple.
Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)</pre>
<a name='selectservice'></a><h4 class='functitle'>selectservice(<span class='sig'></span>)
</h4>
<pre class='doc'>
Displays a GUI which allows the end user to select a service from a list of
discovered devices and their services.
Returns the selected service as a (device-address, service-port, service-
name) tuple. Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.</pre>
<a name='gethostaddr'></a><h4 class='functitle'>gethostaddr(<span class='sig'></span>)
</h4>
<pre class='doc'>
Returns the address of the local bluetooth device.
Raise BluetoothError if the local device is not available.</pre>
<a name='gethostclass'></a><h4 class='functitle'>gethostclass(<span class='sig'></span>)
</h4>
<pre class='doc'>
Returns the class of device of the local bluetooth device.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Raise BluetoothError if the local device is not available.</pre>
<a name='socket'></a><h4 class='functitle'>socket(<span class='sig'>proto=RFCOMM</span>)
</h4>
<pre class='doc'>
socket(proto=RFCOMM) -> socket object
Returns a new socket object.
Arguments:
- proto=RFCOMM: the type of socket to be created - either L2CAP or
RFCOMM.
Note that L2CAP sockets are not available on Python For Series 60, and
only L2CAP client sockets are supported on Mac OS X and Linux (i.e. you can
connect() the socket but not bind(), accept(), etc.).</pre>
<a name='advertise'></a><h4 class='functitle'>advertise(<span class='sig'>name, sock, servicetype</span>)
</h4>
<pre class='doc'>
Starts advertising a service with the given name, using the given server
socket. Raises BluetoothError if the service cannot be advertised.
Arguments:
- name: name of the service to be advertised
- sock: the socket object that will serve this service. The socket must
be already bound to a channel. If a RFCOMM service is being
advertised, the socket should also be listening.
- servicetype: the type of service to advertise - either RFCOMM or
OBEX. (L2CAP services are not currently supported.)
(If the servicetype is RFCOMM, the service will be advertised with the
Serial Port Profile; if the servicetype is OBEX, the service will be
advertised with the OBEX Object Push Profile.)</pre>
<a name='stopadvertise'></a><h4 class='functitle'>stopadvertise(<span class='sig'>sock</span>)
</h4>
<pre class='doc'>
Stops advertising the service on the given socket. Raises BluetoothError if
no service is advertised on the socket.
This will error if the given socket is already closed.</pre>
<a name='splitclass'></a><h4 class='functitle'>splitclass(<span class='sig'>classofdevice</span>)
</h4>
<pre class='doc'> Splits the given class of device to return a 3-item tuple with the
major service class, major device class and minor device class values.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Example:
<pre class='python'><code> <span class="interpreter">>>></span> splitclass(<span class='number'>1057036</span>)
(<span class='number'>129</span>, <span class='number'>1</span>, <span class='number'>3</span>)
<span class="interpreter">>>></span></code></pre></pre>
</div>
<div id='variables' class='section'>
<h2 class='sectiontitle'>Data</h2>
<h4 class='variable'>L2CAP = 10</h4>
<h4 class='variable'>RFCOMM = 11</h4>
<h4 class='variable'>OBEX = 12</h4>
</div>
</div>
</body></html> | 9,834 | index | html | en | html | code | {"qsc_code_num_words": 1413, "qsc_code_num_chars": 9834.0, "qsc_code_mean_word_length": 4.81740977, "qsc_code_frac_words_unique": 0.2059448, "qsc_code_frac_chars_top_2grams": 0.04230939, "qsc_code_frac_chars_top_3grams": 0.03878361, "qsc_code_frac_chars_top_4grams": 0.0290877, "qsc_code_frac_chars_dupe_5grams": 0.39532834, "qsc_code_frac_chars_dupe_6grams": 0.32451888, "qsc_code_frac_chars_dupe_7grams": 0.28074041, "qsc_code_frac_chars_dupe_8grams": 0.23182019, "qsc_code_frac_chars_dupe_9grams": 0.20655208, "qsc_code_frac_chars_dupe_10grams": 0.20655208, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01084813, "qsc_code_frac_chars_whitespace": 0.17510677, "qsc_code_size_file_byte": 9834.0, "qsc_code_num_lines": 233.0, "qsc_code_num_chars_line_max": 191.0, "qsc_code_num_chars_line_mean": 42.20600858, "qsc_code_frac_chars_alphabet": 0.82827909, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.33510638, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.09537367, "qsc_code_frac_chars_long_word_length": 0.00589731, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codehtml_cate_ast": 1.0, "qsc_codehtml_frac_words_text": 0.66524303, "qsc_codehtml_num_chars_text": 6542.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_codehtml_cate_ast": 0, "qsc_codehtml_frac_words_text": 0, "qsc_codehtml_num_chars_text": 0} |
0-1-0/lightblue-0.4 | doc/lightblue.obex-OBEXClient.html | <html>
<head>
<title>OBEXClient</title>
<link rel='stylesheet' href='shortdoc.css' />
</head>
<body>
<h2 class='moduletitle'>module <span class='modulename'><a href='index.html'>lightblue</a>.<a href='lightblue.obex.html'>obex</a>:</span></h2>
<div class='class'>
<h3 class='classtitle'>class <span class='classname'>OBEXClient</span> </h3>
<pre class='doc'> An OBEX client class. (Note this is not available on Python for Series 60.)
For example, to connect to an OBEX server and send a file:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>import</span> lightblue
<span class="interpreter">>>></span> client = lightblue.obex.OBEXClient(<span class='string'>"aa:bb:cc:dd:ee:ff"</span>, <span class='number'>10</span>)
<span class="interpreter">>>></span> client.connect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> client.put({<span class='string'>"name"</span>: <span class='string'>"photo.jpg"</span>}, file(<span class='string'>"photo.jpg"</span>, <span class='string'>"rb"</span>))
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> client.disconnect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span></code></pre>
A client must call connect() to establish a connection before it can send
any other requests.
The connect(), disconnect(), put(), delete(), get() and setpath() methods
all accept the request headers as a dictionary of header-value mappings. The
request headers are used to provide the server with additional information
for the request. For example, this sends a Put request that includes Name,
Type and Length headers in the request headers, to provide details about
the transferred file:
<pre class='python'><code> <span class="interpreter">>>></span> f = file(<span class='string'>"file.txt"</span>)
<span class="interpreter">>>></span> client.put({<span class='string'>"name"</span>: <span class='string'>"file.txt"</span>, <span class='string'>"type"</span>: <span class='string'>"text/plain"</span>,
... <span class='string'>"length"</span>: <span class='number'>5192</span>}, f)
<span class="interpreter">>>></span></code></pre>
Here is a list of all the different string header keys that you can use in
the request headers, and the expected type of the value for each header:
- "name" -> a string
- "type" -> a string
- "length" -> an int
- "time" -> a datetime object from the datetime module
- "description" -> a string
- "target" -> a string or buffer
- "http" -> a string or buffer
- "who" -> a string or buffer
- "connection-id" -> an int
- "application-parameters" -> a string or buffer
- "authentication-challenge" -> a string or buffer
- "authentication-response" -> a string or buffer
- "creator-id" -> an int
- "wan-uuid" -> a string or buffer
- "object-class" -> a string or buffer
- "session-parameters" -> a string or buffer
- "session-sequence-number" -> an int less than 256
(The string header keys are not case-sensitive.)
Alternatively, you can use raw header ID values instead of the above
convenience strings. So, the previous example can be rewritten as:
<pre class='python'><code> <span class="interpreter">>>></span> client.put({<span class='number'>0x01</span>: <span class='string'>"file.txt"</span>, <span class='number'>0x42</span>: <span class='string'>"text/plain"</span>, <span class='number'>0xC3</span>: <span class='number'>5192</span>},
... fileobject)
<span class="interpreter">>>></span></code></pre>
This is also useful for inserting custom headers. For example, a PutImage
request for a Basic Imaging client requires the Img-Descriptor (0x71)
header:
<pre class='python'><code> <span class="interpreter">>>></span> client.put({<span class='string'>"type"</span>: <span class='string'>"x-bt/img-img"</span>,
... <span class='string'>"name"</span>: <span class='string'>"photo.jpg"</span>,
... <span class='number'>0x71</span>: <span class='string'>'<image-descriptor version="1.0"><image encoding="JPEG" pixel="160*120" size="37600"/></image-descriptor>'</span>},
... file(<span class='string'>'photo.jpg'</span>, <span class='string'>'rb'</span>))
<span class="interpreter">>>></span></code></pre>
Notice that the connection-id header is not sent, because this is
automatically included by OBEXClient in the request headers if a
connection-id was received in a previous Connect response.
See the included src/examples/obex_ftp_client.py for an example of using
OBEXClient to implement a File Transfer client for browsing the files on a
remote device.
</pre>
<div id='methods' class='section'>
<h2 class='sectiontitle'>Methods</h2>
<div id='functionlinks'>
<ul>
<li><a href='#__init__'><strong>__init__</strong>(<span class='sig'>address, channel</span>)
</a></li>
<li><a href='#connect'><strong>connect</strong>(<span class='sig'>headers={}</span>)
</a></li>
<li><a href='#disconnect'><strong>disconnect</strong>(<span class='sig'>headers={}</span>)
</a></li>
<li><a href='#put'><strong>put</strong>(<span class='sig'>headers, fileobj</span>)
</a></li>
<li><a href='#delete'><strong>delete</strong>(<span class='sig'>headers</span>)
</a></li>
<li><a href='#get'><strong>get</strong>(<span class='sig'>headers, fileobj</span>)
</a></li>
<li><a href='#setpath'><strong>setpath</strong>(<span class='sig'>headers, cdtoparent=False, createdirs=False</span>)
</a></li>
</ul>
</div>
<a name='__init__'></a><h4 class='methodtitle'>__init__(<span class='sig'>address, channel</span>)
</h4>
<pre class='doc'>
Creates an OBEX client.
Arguments:
- address: the address of the remote device
- channel: the RFCOMM channel of the remote OBEX service</pre>
<a name='connect'></a><h4 class='methodtitle'>connect(<span class='sig'>headers={}</span>)
</h4>
<pre class='doc'>
Establishes the Bluetooth connection to the remote OBEX server and sends
a Connect request to open the OBEX session. Returns an OBEXResponse
instance containing the server response.
Raises lightblue.obex.OBEXError if the session is already connected, or if
an error occurs during the request.
If the server refuses the Connect request (i.e. if it sends a response code
other than OK/Success), the Bluetooth connection will be closed.
Arguments:
- headers={}: the headers to send for the Connect request</pre>
<a name='disconnect'></a><h4 class='methodtitle'>disconnect(<span class='sig'>headers={}</span>)
</h4>
<pre class='doc'>
Sends a Disconnect request to end the OBEX session and closes the Bluetooth
connection to the remote OBEX server. Returns an OBEXResponse
instance containing the server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers={}: the headers to send for the request</pre>
<a name='put'></a><h4 class='methodtitle'>put(<span class='sig'>headers, fileobj</span>)
</h4>
<pre class='doc'> Sends a Put request. Returns an OBEXResponse instance containing the
server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request
- fileobj: a file-like object containing the file data to be sent for
the request
For example, to send a file named 'photo.jpg', using the request headers
to notify the server of the file's name, MIME type and length:
<pre class='python'><code> <span class="interpreter">>>></span> client = lightblue.obex.OBEXClient(<span class='string'>"aa:bb:cc:dd:ee:ff"</span>, <span class='number'>10</span>)
<span class="interpreter">>>></span> client.connect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> client.put({<span class='string'>"name"</span>: <span class='string'>"photo.jpg"</span>, <span class='string'>"type"</span>: <span class='string'>"image/jpeg"</span>,
<span class='string'>"length"</span>: <span class='number'>28566</span>}, file(<span class='string'>"photo.jpg"</span>, <span class='string'>"rb"</span>))
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span></code></pre></pre>
<a name='delete'></a><h4 class='methodtitle'>delete(<span class='sig'>headers</span>)
</h4>
<pre class='doc'> Sends a Put-Delete request in order to delete a file or folder on the remote
server. Returns an OBEXResponse instance containing the server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request - you should use the
'name' header to specify the file you want to delete
If the file on the server can't be deleted because it's a read-only file,
you might get an 'Unauthorized' response, like this:
<pre class='python'><code> <span class="interpreter">>>></span> client = lightblue.obex.OBEXClient(<span class='string'>"aa:bb:cc:dd:ee:ff"</span>, <span class='number'>10</span>)
<span class="interpreter">>>></span> client.connect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> client.delete({<span class='string'>"name"</span>: <span class='string'>"random_file.txt"</span>})
<OBEXResponse reason=<span class='string'>'Unauthorized'</span> code=<span class='number'>0x41</span> (<span class='number'>0xc1</span>) headers={}>
<span class="interpreter">>>></span></code></pre></pre>
<a name='get'></a><h4 class='methodtitle'>get(<span class='sig'>headers, fileobj</span>)
</h4>
<pre class='doc'> Sends a Get request. Returns an OBEXResponse instance containing the server
response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request - you should use these
to specify the file you want to retrieve
- fileobj: a file-like object, to which the received data will be
written
An example:
<pre class='python'><code> <span class="interpreter">>>></span> client.connect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> f = file(<span class='string'>"received_file.txt"</span>, <span class='string'>"w+"</span>)
<span class="interpreter">>>></span> client.get({<span class='string'>"name"</span>: <span class='string'>"testfile.txt"</span>}, f)
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={<span class='string'>'length'</span>:<span class='number'>9</span>}>
<span class="interpreter">>>></span> f.seek(<span class='number'>0</span>)
<span class="interpreter">>>></span> f.read()
<span class='string'>'test file'</span>
<span class="interpreter">>>></span></code></pre></pre>
<a name='setpath'></a><h4 class='methodtitle'>setpath(<span class='sig'>headers, cdtoparent=False, createdirs=False</span>)
</h4>
<pre class='doc'> Sends a SetPath request in order to set the "current path" on the remote
server for file transfers. Returns an OBEXResponse instance containing the
server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request - you should use the
'name' header to specify the directory you want to change to
- cdtoparent=False: True if the remote server should move up one
directory before applying the specified directory (i.e. 'cd
../dirname')
- createdirs=False: True if the specified directory should be created
if it doesn't exist (if False, the server will return an error
response if the directory doesn't exist)
For example:
<pre class='python'><code> <span class='comment'># change to the "images" subdirectory</span>
<span class="interpreter">>>></span> client.setpath({<span class='string'>"name"</span>: <span class='string'>"images"</span>})
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span></code></pre>
<pre class='python'><code> <span class='comment'># change to the parent directory</span>
<span class="interpreter">>>></span> client.setpath({}, cdtoparent=True)
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span></code></pre>
<pre class='python'><code> <span class='comment'># make a directory "My_Files"</span>
<span class="interpreter">>>></span> client.setpath({<span class='string'>"name"</span>: <span class='string'>"My_Files"</span>}, createdirs=True)
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span></code></pre>
<pre class='python'><code> <span class='comment'># change to the root directory - you can use an empty "name" header</span>
<span class='comment'># to specify this</span>
<span class="interpreter">>>></span> client.setpath({<span class='string'>"name"</span>: <span class='string'>""</span>})
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span></code></pre></pre>
</div>
</div>
</body></html> | 16,245 | lightblue.obex-OBEXClient | html | en | html | code | {"qsc_code_num_words": 2331, "qsc_code_num_chars": 16245.0, "qsc_code_mean_word_length": 4.5963106, "qsc_code_frac_words_unique": 0.13470613, "qsc_code_frac_chars_top_2grams": 0.12684338, "qsc_code_frac_chars_top_3grams": 0.07401531, "qsc_code_frac_chars_top_4grams": 0.07186858, "qsc_code_frac_chars_dupe_5grams": 0.65895091, "qsc_code_frac_chars_dupe_6grams": 0.63869703, "qsc_code_frac_chars_dupe_7grams": 0.61433638, "qsc_code_frac_chars_dupe_8grams": 0.60406944, "qsc_code_frac_chars_dupe_9grams": 0.57252193, "qsc_code_frac_chars_dupe_10grams": 0.5213739, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01015752, "qsc_code_frac_chars_whitespace": 0.16368113, "qsc_code_size_file_byte": 16245.0, "qsc_code_num_lines": 267.0, "qsc_code_num_chars_line_max": 311.0, "qsc_code_num_chars_line_mean": 60.84269663, "qsc_code_frac_chars_alphabet": 0.7784484, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.35555556, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.03111111, "qsc_code_frac_chars_string_length": 0.13400222, "qsc_code_frac_chars_long_word_length": 0.00984858, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00763265, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codehtml_cate_ast": 1.0, "qsc_codehtml_frac_words_text": 0.59981533, "qsc_codehtml_num_chars_text": 9744.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 1, "qsc_code_frac_chars_dupe_6grams": 1, "qsc_code_frac_chars_dupe_7grams": 1, "qsc_code_frac_chars_dupe_8grams": 1, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_codehtml_cate_ast": 0, "qsc_codehtml_frac_words_text": 0, "qsc_codehtml_num_chars_text": 0} |
0-1-0/lightblue-0.4 | doc/lightblue.obex-OBEXResponse.html | <html>
<head>
<title>OBEXResponse</title>
<link rel='stylesheet' href='shortdoc.css' />
</head>
<body>
<h2 class='moduletitle'>module <span class='modulename'><a href='index.html'>lightblue</a>.<a href='lightblue.obex.html'>obex</a>:</span></h2>
<div class='class'>
<h3 class='classtitle'>class <span class='classname'>OBEXResponse</span> </h3>
<pre class='doc'> Contains the OBEX response received from an OBEX server.
When an OBEX client sends a request, the OBEX server sends back a response
code (to indicate whether the request was successful) and a set of response
headers (to provide other useful information).
For example, if a client sends a 'Get' request to retrieve a file, the
client might get a response like this:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>import</span> lightblue
<span class="interpreter">>>></span> client = lightblue.obex.OBEXClient(<span class='string'>"aa:bb:cc:dd:ee:ff"</span>, <span class='number'>10</span>)
<span class="interpreter">>>></span> response = client.get({<span class='string'>"name"</span>: <span class='string'>"file.txt"</span>}, file(<span class='string'>"file.txt"</span>, <span class='string'>"w"</span>))
<span class="interpreter">>>></span> <span class='keyword'>print</span> response
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={<span class='string'>'length'</span>: <span class='number'>35288</span>}></code></pre>
You can get the response code and response headers in different formats:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>print</span> response.reason
<span class='string'>'OK'</span> <span class='comment'># a string description of the response code</span>
<span class="interpreter">>>></span> <span class='keyword'>print</span> response.code
<span class='number'>32</span> <span class='comment'># the response code</span>
<span class="interpreter">>>></span> <span class='keyword'>print</span> response.headers
{<span class='string'>'length'</span>: <span class='number'>35288</span>} <span class='comment'># the headers, with string keys</span>
<span class="interpreter">>>></span> <span class='keyword'>print</span> response.rawheaders
{<span class='number'>195</span>: <span class='number'>35288</span>} <span class='comment'># the headers, with raw header ID keys</span>
<span class="interpreter">>>></span></code></pre>
Note how the 'code' attribute does not have the final bit set - e.g. for
OK/Success, the response code is 0x20, not 0xA0.
The lightblue.obex module defines constants for response code values (e.g.
lightblue.obex.OK, lightblue.obex.FORBIDDEN, etc.).
</pre>
<div id='properties' class='section'>
<h2 class='sectiontitle'>Properties</h2>
<h4 class='propertytitle'>code</h4>
<pre class='doc'>The response code, without the final bit set.</pre>
<h4 class='propertytitle'>headers</h4>
<pre class='doc'>The response headers, as a dictionary with string keys.</pre>
<h4 class='propertytitle'>rawheaders</h4>
<pre class='doc'>The response headers, as a dictionary with header ID (unsigned byte) keys.</pre>
<h4 class='propertytitle'>reason</h4>
<pre class='doc'>A string description of the response code.</pre>
</div>
<div id='methods' class='section'>
<h2 class='sectiontitle'>Methods</h2>
<div id='functionlinks'>
<ul>
<li><a href='#getheader'><strong>getheader</strong>(<span class='sig'>header, default=None</span>)
</a></li>
</ul>
</div>
<a name='getheader'></a><h4 class='methodtitle'>getheader(<span class='sig'>header, default=None</span>)
</h4>
<pre class='doc'>
Returns the response header value for the given header, which may
either be a string (not case-sensitive) or the raw byte
value of the header ID.
Returns the specified default value if the header is not present.</pre>
</div>
</div>
</body></html> | 4,188 | lightblue.obex-OBEXResponse | html | en | html | code | {"qsc_code_num_words": 606, "qsc_code_num_chars": 4188.0, "qsc_code_mean_word_length": 4.68646865, "qsc_code_frac_words_unique": 0.25082508, "qsc_code_frac_chars_top_2grams": 0.12676056, "qsc_code_frac_chars_top_3grams": 0.10528169, "qsc_code_frac_chars_top_4grams": 0.06971831, "qsc_code_frac_chars_dupe_5grams": 0.43380282, "qsc_code_frac_chars_dupe_6grams": 0.38591549, "qsc_code_frac_chars_dupe_7grams": 0.34014085, "qsc_code_frac_chars_dupe_8grams": 0.28697183, "qsc_code_frac_chars_dupe_9grams": 0.275, "qsc_code_frac_chars_dupe_10grams": 0.26021127, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01385425, "qsc_code_frac_chars_whitespace": 0.13825215, "qsc_code_size_file_byte": 4188.0, "qsc_code_num_lines": 79.0, "qsc_code_num_chars_line_max": 237.0, "qsc_code_num_chars_line_mean": 53.01265823, "qsc_code_frac_chars_alphabet": 0.77306733, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0625, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.14657436, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00381953, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codehtml_cate_ast": 1.0, "qsc_codehtml_frac_words_text": 0.48877746, "qsc_codehtml_num_chars_text": 2047.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_codehtml_cate_ast": 0, "qsc_codehtml_frac_words_text": 0, "qsc_codehtml_num_chars_text": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRemoveCurse.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Weakness;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.EquipableItem;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.armor.Armor;
import com.shatteredpixel.shatteredpixeldungeon.items.wands.Wand;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.Weapon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.audio.Sample;
public class ScrollOfRemoveCurse extends InventoryScroll {
{
initials = 7;
mode = WndBag.Mode.UNCURSABLE;
}
@Override
public void empoweredRead() {
for (Item item : curUser.belongings){
if (item.cursed){
item.cursedKnown = true;
}
}
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
doRead();
}
@Override
protected void onItemSelected(Item item) {
new Flare( 6, 32 ).show( curUser.sprite, 2f ) ;
boolean procced = uncurse( curUser, item );
Weakness.detach( curUser, Weakness.class );
if (procced) {
GLog.p( Messages.get(this, "cleansed") );
} else {
GLog.i( Messages.get(this, "not_cleansed") );
}
}
public static boolean uncurse( Hero hero, Item... items ) {
boolean procced = false;
for (Item item : items) {
if (item != null) {
item.cursedKnown = true;
if (item.cursed) {
procced = true;
item.cursed = false;
}
}
if (item instanceof Weapon){
Weapon w = (Weapon) item;
if (w.hasCurseEnchant()){
w.enchant(null);
procced = true;
}
}
if (item instanceof Armor){
Armor a = (Armor) item;
if (a.hasCurseGlyph()){
a.inscribe(null);
procced = true;
}
}
if (item instanceof Wand){
((Wand) item).updateLevel();
}
}
if (procced) {
hero.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10 );
hero.updateHT( false ); //for ring of might
updateQuickslot();
}
return procced;
}
public static boolean uncursable( Item item ){
if ((item instanceof EquipableItem || item instanceof Wand) && (!item.isIdentified() || item.cursed)){
return true;
} else if (item instanceof Weapon){
return ((Weapon)item).hasCurseEnchant();
} else if (item instanceof Armor){
return ((Armor)item).hasCurseGlyph();
} else {
return false;
}
}
@Override
public int price() {
return isKnown() ? 30 * quantity : super.price();
}
}
| 3,746 | ScrollOfRemoveCurse | java | en | java | code | {"qsc_code_num_words": 437, "qsc_code_num_chars": 3746.0, "qsc_code_mean_word_length": 6.15331808, "qsc_code_frac_words_unique": 0.40503432, "qsc_code_frac_chars_top_2grams": 0.09483079, "qsc_code_frac_chars_top_3grams": 0.21197471, "qsc_code_frac_chars_top_4grams": 0.22908144, "qsc_code_frac_chars_dupe_5grams": 0.24209743, "qsc_code_frac_chars_dupe_6grams": 0.08478988, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00935786, "qsc_code_frac_chars_whitespace": 0.17271757, "qsc_code_size_file_byte": 3746.0, "qsc_code_num_lines": 128.0, "qsc_code_num_chars_line_max": 105.0, "qsc_code_num_chars_line_mean": 29.265625, "qsc_code_frac_chars_alphabet": 0.8583414, "qsc_code_frac_chars_comments": 0.21356113, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.14893617, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00678887, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07446809, "qsc_codejava_score_lines_no_logic": 0.27659574, "qsc_codejava_frac_words_no_modifier": 0.625, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTeleportation.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.secret.SecretRoom;
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.SpecialRoom;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.tweeners.AlphaTweener;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Point;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class ScrollOfTeleportation extends Scroll {
{
initials = 8;
}
@Override
public void doRead() {
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
teleportPreferringUnseen( curUser );
setKnown();
readAnimation();
}
@Override
public void empoweredRead() {
if (Dungeon.bossLevel()){
GLog.w( Messages.get(this, "no_tele") );
return;
}
GameScene.selectCell(new CellSelector.Listener() {
@Override
public void onSelect(Integer target) {
if (target != null) {
//time isn't spent
((HeroSprite)curUser.sprite).read();
teleportToLocation(curUser, target);
}
}
@Override
public String prompt() {
return Messages.get(ScrollOfTeleportation.class, "prompt");
}
});
}
public static void teleportToLocation(Hero hero, int pos){
PathFinder.buildDistanceMap(pos, BArray.or(Dungeon.level.passable, Dungeon.level.avoid, null));
if (PathFinder.distance[hero.pos] == Integer.MAX_VALUE
|| (!Dungeon.level.passable[pos] && !Dungeon.level.avoid[pos])
|| Actor.findChar(pos) != null){
GLog.w( Messages.get(ScrollOfTeleportation.class, "cant_reach") );
return;
}
appear( hero, pos );
Dungeon.level.occupyCell(hero );
Dungeon.observe();
GameScene.updateFog();
}
public static void teleportHero( Hero hero ) {
if (Dungeon.bossLevel()){
GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") );
return;
}
int count = 10;
int pos;
do {
pos = Dungeon.level.randomRespawnCell();
if (count-- <= 0) {
break;
}
} while (pos == -1);
if (pos == -1) {
GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") );
} else {
GLog.i( Messages.get(ScrollOfTeleportation.class, "tele") );
appear( hero, pos );
Dungeon.level.occupyCell(hero );
Dungeon.observe();
GameScene.updateFog();
}
}
public static void teleportPreferringUnseen( Hero hero ){
if (Dungeon.bossLevel() || !(Dungeon.level instanceof RegularLevel)){
teleportHero( hero );
return;
}
RegularLevel level = (RegularLevel) Dungeon.level;
ArrayList<Integer> candidates = new ArrayList<>();
for (Room r : level.rooms()){
if (r instanceof SpecialRoom){
int terr;
boolean locked = false;
for (Point p : r.getPoints()){
terr = level.map[level.pointToCell(p)];
if (terr == Terrain.LOCKED_DOOR || terr == Terrain.BARRICADE){
locked = true;
break;
}
}
if (locked){
continue;
}
}
int cell;
for (Point p : r.charPlaceablePoints(level)){
cell = level.pointToCell(p);
if (level.passable[cell] && !level.visited[cell] && Actor.findChar(cell) == null){
candidates.add(cell);
}
}
}
if (candidates.isEmpty()){
teleportHero( hero );
} else {
int pos = Random.element(candidates);
boolean secretDoor = false;
int doorPos = -1;
if (level.room(pos) instanceof SpecialRoom){
SpecialRoom room = (SpecialRoom) level.room(pos);
if (room.entrance() != null){
doorPos = level.pointToCell(room.entrance());
for (int i : PathFinder.NEIGHBOURS8){
if (!room.inside(level.cellToPoint(doorPos + i))
&& level.passable[doorPos + i]
&& Actor.findChar(doorPos + i) == null){
secretDoor = room instanceof SecretRoom;
pos = doorPos + i;
break;
}
}
}
}
GLog.i( Messages.get(ScrollOfTeleportation.class, "tele") );
appear( hero, pos );
Dungeon.level.occupyCell(hero );
if (secretDoor && level.map[doorPos] == Terrain.SECRET_DOOR){
Sample.INSTANCE.play( Assets.SND_SECRET );
int oldValue = Dungeon.level.map[doorPos];
GameScene.discoverTile( doorPos, oldValue );
Dungeon.level.discover( doorPos );
ScrollOfMagicMapping.discover( doorPos );
}
Dungeon.observe();
GameScene.updateFog();
}
}
public static void appear( Char ch, int pos ) {
ch.sprite.interruptMotion();
ch.move( pos );
if (ch.pos == pos) ch.sprite.place( pos );
if (ch.invisible == 0) {
ch.sprite.alpha( 0 );
ch.sprite.parent.add( new AlphaTweener( ch.sprite, 1, 0.4f ) );
}
ch.sprite.emitter().start( Speck.factory(Speck.LIGHT), 0.2f, 3 );
Sample.INSTANCE.play( Assets.SND_TELEPORT );
}
@Override
public int price() {
return isKnown() ? 30 * quantity : super.price();
}
}
| 6,634 | ScrollOfTeleportation | java | en | java | code | {"qsc_code_num_words": 744, "qsc_code_num_chars": 6634.0, "qsc_code_mean_word_length": 6.21774194, "qsc_code_frac_words_unique": 0.32526882, "qsc_code_frac_chars_top_2grams": 0.04474708, "qsc_code_frac_chars_top_3grams": 0.15607436, "qsc_code_frac_chars_top_4grams": 0.17120623, "qsc_code_frac_chars_dupe_5grams": 0.30328578, "qsc_code_frac_chars_dupe_6grams": 0.16515348, "qsc_code_frac_chars_dupe_7grams": 0.10830091, "qsc_code_frac_chars_dupe_8grams": 0.08668396, "qsc_code_frac_chars_dupe_9grams": 0.06593169, "qsc_code_frac_chars_dupe_10grams": 0.06593169, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00641613, "qsc_code_frac_chars_whitespace": 0.17772083, "qsc_code_size_file_byte": 6634.0, "qsc_code_num_lines": 233.0, "qsc_code_num_chars_line_max": 98.0, "qsc_code_num_chars_line_mean": 28.472103, "qsc_code_frac_chars_alphabet": 0.8416132, "qsc_code_frac_chars_comments": 0.12044016, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.1954023, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00771208, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05747126, "qsc_codejava_score_lines_no_logic": 0.24137931, "qsc_codejava_frac_words_no_modifier": 0.81818182, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | examples/file_receive.py | """
Shows how to receive a file over OBEX.
"""
import lightblue
# bind the socket, and advertise an OBEX service
sock = lightblue.socket()
try:
sock.bind(("", 0)) # bind to 0 to bind to a dynamically assigned channel
lightblue.advertise("LightBlue example OBEX service", sock, lightblue.OBEX)
# Receive a file and save it as MyFile.txt.
# This will wait and block until a file is received.
print "Waiting to receive file on channel %d..." % sock.getsockname()[1]
lightblue.obex.recvfile(sock, "MyFile.txt")
finally:
sock.close()
print "Saved received file to MyFile.txt!"
# Please note:
#
# To use a file through this example, the other device must send the file to
# the correct channel. E.g. if this example prints "Waiting to receive file on
# channel 5..." the remote device must send the file specifically to channel 5.
#
# * But what if you can't specify a channel or service?
#
# If you can send a file to a specific channel - e.g. by using
# lightblue.obex.sendfile(), as the send_file.py example does - then you
# should be fine.
#
# But, if you're just using the system's default OBEX file-sending tool on
# the other device (e.g. "Send file..." from the Bluetooth drop-down menu on
# Mac OS X, or "Send ... Via Bluetooth" on Series 60 phones), it may only
# allow you to choose a device to send the file to, without choosing a
# specific channel or service on the device. In this case, the tool is
# probably just choosing the first available OBEX service on the device.
#
# So if you switch off all other related services, this example's service
# should automatically receive all OBEX files. E.g. if you're running this
# example on Mac OS X, go to the System Preferences' Bluetooth panel: on
# Mac OS X 10.4, go to the "Sharing" tab, and uncheck the "On" checkboxes for
# the "Bluetooth File Transfer" and "Bluetooth File Exchange" services.
# On Mac OS X 10.3, go to the "File Exchange" tab, and for "When receiving
# items", select "Refuse all", and uncheck "Allow other devices to browse
# files on this computer".
| 2,134 | file_receive | py | en | python | code | {"qsc_code_num_words": 350, "qsc_code_num_chars": 2134.0, "qsc_code_mean_word_length": 4.27714286, "qsc_code_frac_words_unique": 0.39714286, "qsc_code_frac_chars_top_2grams": 0.01670007, "qsc_code_frac_chars_top_3grams": 0.01870407, "qsc_code_frac_chars_top_4grams": 0.02137609, "qsc_code_frac_chars_dupe_5grams": 0.08016032, "qsc_code_frac_chars_dupe_6grams": 0.03874415, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00776583, "qsc_code_frac_chars_whitespace": 0.21555764, "qsc_code_size_file_byte": 2134.0, "qsc_code_num_lines": 50.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 42.68, "qsc_code_frac_chars_alphabet": 0.8864994, "qsc_code_frac_chars_comments": 0.77272727, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.28009828, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 0.0, "qsc_codepython_frac_lines_func_ratio": null, "qsc_codepython_cate_var_zero": null, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.1, "qsc_codepython_frac_lines_simplefunc": null, "qsc_codepython_score_lines_no_logic": null, "qsc_codepython_frac_lines_print": 0.2} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 1, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | examples/obex_ftp_client.py | '''
This example shows how to use the lightblue.obex.OBEXClient class to implement a
basic client for the File Transfer Profile, which is a profile implemented on
top of OBEX. This profile allows clients to:
- send files
- retrieve files
- create and remove directories
- change the current working directory
You can find a copy of the profile specification at
<http://www.bluetooth.com/Bluetooth/Technology/Building/Specifications/>.
'''
import sys
import os
import lightblue
# This is the special Target UUID (F9EC7BC4-953C-11D2-984E-525400DC9E09) for the
# File Transfer Profile, in byte form. You can get this in Python 2.5 using the
# uuid module:
# >>> print uuid.UUID('{F9EC7BC4-953C-11D2-984E-525400DC9E09}').bytes
FTP_TARGET_UUID = '\xf9\xec{\xc4\x95<\x11\xd2\x98NRT\x00\xdc\x9e\t'
# A note about Connection ID headers:
# Notice that the FTPClient does not send the Connection ID in any of the
# request headers, even though this is required by the File Transfer Profile
# specs. This is because the OBEXClient class automatically sends the Connection
# ID with each request if it received one from the server in the initial Connect
# response headers, so you do not have to add it yourself.
class FTPClient(object):
def __init__(self, address, port):
self.client = lightblue.obex.OBEXClient(address, port)
def connect(self):
response = self.client.connect({'target': FTP_TARGET_UUID})
if response.code != lightblue.obex.OK:
raise Exception('OBEX server refused Connect request (server \
response was "%s")' % response.reason)
def disconnect(self):
print "Disconnecting..."
response = self.client.disconnect()
print 'Server response:', response.reason
def ls(self):
import StringIO
dirlist = StringIO.StringIO()
response = self.client.get({'type': 'x-obex/folder-listing'}, dirlist)
print 'Server response:', response.reason
if response.code == lightblue.obex.OK:
files = self._parsefolderlisting(dirlist.getvalue())
if len(files) == 0:
print 'No files found'
else:
print 'Found files:'
for f in files:
print '\t', f
def cd(self, dirname):
if dirname == os.sep:
# change to root dir
response = self.client.setpath({'name': ''})
elif dirname == '..':
# change to parent directory
response = self.client.setpath({}, cdtoparent=True)
else:
# change to subdirectory
response = self.client.setpath({'name': dirname})
print 'Server response:', response.reason
def put(self, filename):
print 'Sending %s...' % filename
try:
f = file(filename, 'rb')
except Exception, e:
print "Cannot open file %s" % filename
return
response = self.client.put({'name': os.path.basename(filename)}, f)
f.close()
print 'Server response:', response.reason
def get(self, filename):
if os.path.isfile(filename):
if raw_input("Overwrite local file %s?" % filename).lower() != "y":
return
print 'Retrieving %s...' % filename
f = file(filename, 'wb')
response = self.client.get({'name': filename}, f)
f.close()
print 'Server response:', response.reason
def rm(self, filename):
response = self.client.delete({'name': filename})
print 'Server response:', response.reason
def mkdir(self, dirname):
response = self.client.setpath({'name': dirname}, createdirs=True)
print 'Server response:', response.reason
def rmdir(self, dirname):
response = self.client.delete({'name': dirname})
print 'Server response:', response.reason
if response.code == lightblue.obex.PRECONDITION_FAILED:
print 'Directory contents must be deleted first'
def _parsefolderlisting(self, xmldata):
"""
Returns a list of basic details for the files and folders contained in
the given XML folder-listing data. (The complete folder-listing XML DTD
is documented in the IrOBEX specification.)
"""
if len(xmldata) == 0:
print "Error parsing folder-listing XML: no xml data"
return []
entries = []
import xml.dom.minidom
import xml.parsers.expat
try:
dom = xml.dom.minidom.parseString(xmldata)
except xml.parsers.expat.ExpatError, e:
print "Error parsing folder-listing XML (%s): '%s'" % \
(str(e), xmldata)
return []
parent = dom.getElementsByTagName('parent-folder')
if len(parent) != 0:
entries.append('..')
folders = dom.getElementsByTagName('folder')
for f in folders:
entries.append('%s/\t%s' % (f.getAttribute('name'),
f.getAttribute('size')))
files = dom.getElementsByTagName('file')
for f in files:
entries.append('%s\t%s' % (f.getAttribute('name'),
f.getAttribute('size')))
return entries
def processcommands(ftpclient):
while True:
input = raw_input('\nEnter command: ')
cmd = input.split(" ")[0].lower()
if not cmd:
continue
if cmd == 'exit':
break
try:
method = getattr(ftpclient, cmd)
except AttributeError:
print 'Unknown command "%s".' % cmd
print main.__doc__
continue
if cmd == 'ls':
if " " in input.strip():
print "(Ignoring path, can only list contents of current dir)"
method()
else:
name = input[len(cmd)+1:] # file or directory name required
method(name)
def main():
"""
Usage: python obex_ftp_client.py [address channel]
If the address and channel are not provided, the user will be prompted to
choose a service.
Once the client is connected, you can enter one of these commands:
ls
cd <directory> (use '..' to change to parent, or '/' to change to root)
put <file>
get <file>
rm <file>
mkdir <directory>
rmdir <directory>
exit
Some servers accept "/" path separators within the <file> or <filename>
arguments. Otherwise, you will have to just send either a single directory
or filename, without any paths.
"""
if len(sys.argv) > 1:
address = sys.argv[1]
channel = int(sys.argv[2])
else:
# ask user to choose a service
# a FTP service is usually called 'FTP', 'OBEX File Transfer', etc.
address, channel, servicename = lightblue.selectservice()
print 'Connecting to %s on channel %d...' % (address, channel)
ftpclient = FTPClient(address, channel)
ftpclient.connect()
print 'Connected.'
try:
processcommands(ftpclient)
finally:
try:
ftpclient.disconnect()
except Exception, e:
print "Error while disconnecting:", e
pass
if __name__ == "__main__":
main()
| 7,356 | obex_ftp_client | py | en | python | code | {"qsc_code_num_words": 862, "qsc_code_num_chars": 7356.0, "qsc_code_mean_word_length": 5.06148492, "qsc_code_frac_words_unique": 0.32946636, "qsc_code_frac_chars_top_2grams": 0.02750401, "qsc_code_frac_chars_top_3grams": 0.04538162, "qsc_code_frac_chars_top_4grams": 0.04950722, "qsc_code_frac_chars_dupe_5grams": 0.19963328, "qsc_code_frac_chars_dupe_6grams": 0.16456567, "qsc_code_frac_chars_dupe_7grams": 0.08640843, "qsc_code_frac_chars_dupe_8grams": 0.07380243, "qsc_code_frac_chars_dupe_9grams": 0.07380243, "qsc_code_frac_chars_dupe_10grams": 0.07380243, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01241032, "qsc_code_frac_chars_whitespace": 0.29893964, "qsc_code_size_file_byte": 7356.0, "qsc_code_num_lines": 213.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 34.53521127, "qsc_code_frac_chars_alphabet": 0.8336242, "qsc_code_frac_chars_comments": 0.11364872, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.23308271, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0075188, "qsc_code_frac_chars_string_length": 0.13893189, "qsc_code_frac_chars_long_word_length": 0.01315789, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 0.0, "qsc_codepython_frac_lines_func_ratio": null, "qsc_codepython_cate_var_zero": null, "qsc_codepython_frac_lines_pass": 0.0075188, "qsc_codepython_frac_lines_import": 0.04511278, "qsc_codepython_frac_lines_simplefunc": null, "qsc_codepython_score_lines_no_logic": null, "qsc_codepython_frac_lines_print": 0.18045113} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 1, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/_IOBluetooth.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"""
Provides a python interface to the Mac OSX IOBluetooth Framework classes,
through PyObjC.
For example:
>>> from lightblue import _IOBluetooth
>>> for d in _IOBluetooth.IOBluetoothDevice.recentDevices_(0):
... print d.getName()
...
Munkey
Adam
My Nokia 6600
>>>
See http://developer.apple.com/documentation/DeviceDrivers/Reference/IOBluetooth/index.html
for Apple's IOBluetooth documentation.
See http://pyobjc.sourceforge.net for details on how to access Objective-C
classes through PyObjC.
"""
import objc
try:
# mac os 10.5 loads frameworks using bridgesupport metadata
__bundle__ = objc.initFrameworkWrapper("IOBluetooth",
frameworkIdentifier="com.apple.IOBluetooth",
frameworkPath=objc.pathForFramework(
"/System/Library/Frameworks/IOBluetooth.framework"),
globals=globals())
except (AttributeError, ValueError):
# earlier versions use loadBundle() and setSignatureForSelector()
objc.loadBundle("IOBluetooth", globals(),
bundle_path=objc.pathForFramework(u'/System/Library/Frameworks/IOBluetooth.framework'))
# Sets selector signatures in order to receive arguments correctly from
# PyObjC methods. These MUST be set, otherwise the method calls won't work
# at all, mostly because you can't pass by pointers in Python.
# set to return int, and take an unsigned char output arg
# i.e. in python: return (int, unsigned char) and accept no args
objc.setSignatureForSelector("IOBluetoothSDPServiceRecord",
"getRFCOMMChannelID:", "i12@0:o^C")
# set to return int, and take an unsigned int output arg
# i.e. in python: return (int, unsigned int) and accept no args
objc.setSignatureForSelector("IOBluetoothSDPServiceRecord",
"getL2CAPPSM:", "i12@0:o^S")
# set to return int, and take (output object, unsigned char, object) args
# i.e. in python: return (int, object) and accept (unsigned char, object)
objc.setSignatureForSelector("IOBluetoothDevice",
"openRFCOMMChannelSync:withChannelID:delegate:", "i16@0:o^@C@")
# set to return int, and take (output object, unsigned int, object) args
# i.e. in python: return (int, object) and accept (unsigned int, object)
objc.setSignatureForSelector("IOBluetoothDevice",
"openL2CAPChannelSync:withPSM:delegate:", "i20@0:o^@I@")
# set to return int, take a const 6-char array arg
# i.e. in python: return object and accept 6-char list
# this seems to work even though the selector doesn't take a char aray,
# it takes a struct 'BluetoothDeviceAddress' which contains a char array.
objc.setSignatureForSelector("IOBluetoothDevice",
"withAddress:", '@12@0:r^[6C]')
del objc
| 3,570 | _IOBluetooth | py | en | python | code | {"qsc_code_num_words": 455, "qsc_code_num_chars": 3570.0, "qsc_code_mean_word_length": 5.47692308, "qsc_code_frac_words_unique": 0.45714286, "qsc_code_frac_chars_top_2grams": 0.03250401, "qsc_code_frac_chars_top_3grams": 0.02207063, "qsc_code_frac_chars_top_4grams": 0.02808989, "qsc_code_frac_chars_dupe_5grams": 0.26123596, "qsc_code_frac_chars_dupe_6grams": 0.21629213, "qsc_code_frac_chars_dupe_7grams": 0.18619583, "qsc_code_frac_chars_dupe_8grams": 0.13081862, "qsc_code_frac_chars_dupe_9grams": 0.11436597, "qsc_code_frac_chars_dupe_10grams": 0.04173355, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01172291, "qsc_code_frac_chars_whitespace": 0.21148459, "qsc_code_size_file_byte": 3570.0, "qsc_code_num_lines": 86.0, "qsc_code_num_chars_line_max": 95.0, "qsc_code_num_chars_line_mean": 41.51162791, "qsc_code_frac_chars_alphabet": 0.87353464, "qsc_code_frac_chars_comments": 0.6557423, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.23809524, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.35462185, "qsc_code_frac_chars_long_word_length": 0.21344538, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.04761905, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.04761905, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfLightning.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Lightning;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.SparkParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.enchantments.Shocking;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.Camera;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class WandOfLightning extends DamageWand {
{
image = ItemSpriteSheet.WAND_LIGHTNING;
}
private ArrayList<Char> affected = new ArrayList<>();
private ArrayList<Lightning.Arc> arcs = new ArrayList<>();
public int min(int lvl){
return 5+lvl;
}
public int max(int lvl){
return 10+5*lvl;
}
@Override
protected void onZap( Ballistica bolt ) {
//lightning deals less damage per-target, the more targets that are hit.
float multipler = 0.4f + (0.6f/affected.size());
//if the main target is in water, all affected take full damage
if (Dungeon.level.water[bolt.collisionPos]) multipler = 1f;
for (Char ch : affected){
processSoulMark(ch, chargesPerCast());
ch.damage(Math.round(damageRoll() * multipler), this);
if (ch == Dungeon.hero) Camera.main.shake( 2, 0.3f );
ch.sprite.centerEmitter().burst( SparkParticle.FACTORY, 3 );
ch.sprite.flash();
}
if (!curUser.isAlive()) {
Dungeon.fail( getClass() );
GLog.n(Messages.get(this, "ondeath"));
}
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
//acts like shocking enchantment
new Shocking().proc(staff, attacker, defender, damage);
}
private void arc( Char ch ) {
int dist = (Dungeon.level.water[ch.pos] && !ch.flying) ? 2 : 1;
ArrayList<Char> hitThisArc = new ArrayList<>();
PathFinder.buildDistanceMap( ch.pos, BArray.not( Dungeon.level.solid, null ), dist );
for (int i = 0; i < PathFinder.distance.length; i++) {
if (PathFinder.distance[i] < Integer.MAX_VALUE){
Char n = Actor.findChar( i );
if (n == Dungeon.hero && PathFinder.distance[i] > 1)
//the hero is only zapped if they are adjacent
continue;
else if (n != null && !affected.contains( n )) {
hitThisArc.add(n);
}
}
}
affected.addAll(hitThisArc);
for (Char hit : hitThisArc){
arcs.add(new Lightning.Arc(ch.sprite.center(), hit.sprite.center()));
arc(hit);
}
}
@Override
protected void fx( Ballistica bolt, Callback callback ) {
affected.clear();
arcs.clear();
int cell = bolt.collisionPos;
Char ch = Actor.findChar( cell );
if (ch != null) {
affected.add( ch );
arcs.add( new Lightning.Arc(curUser.sprite.center(), ch.sprite.center()));
arc(ch);
} else {
arcs.add( new Lightning.Arc(curUser.sprite.center(), DungeonTilemap.raisedTileCenterToWorld(bolt.collisionPos)));
CellEmitter.center( cell ).burst( SparkParticle.FACTORY, 3 );
}
//don't want to wait for the effect before processing damage.
curUser.sprite.parent.addToFront( new Lightning( arcs, null ) );
Sample.INSTANCE.play( Assets.SND_LIGHTNING );
callback.call();
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
particle.color(0xFFFFFF);
particle.am = 0.6f;
particle.setLifespan(0.6f);
particle.acc.set(0, +10);
particle.speed.polar(-Random.Float(3.1415926f), 6f);
particle.setSize(0f, 1.5f);
particle.sizeJitter = 1f;
particle.shuffleXY(1f);
float dst = Random.Float(1f);
particle.x -= dst;
particle.y += dst;
}
}
| 5,132 | WandOfLightning | java | en | java | code | {"qsc_code_num_words": 645, "qsc_code_num_chars": 5132.0, "qsc_code_mean_word_length": 5.84496124, "qsc_code_frac_words_unique": 0.39844961, "qsc_code_frac_chars_top_2grams": 0.04774536, "qsc_code_frac_chars_top_3grams": 0.16127321, "qsc_code_frac_chars_top_4grams": 0.17506631, "qsc_code_frac_chars_dupe_5grams": 0.17161804, "qsc_code_frac_chars_dupe_6grams": 0.06578249, "qsc_code_frac_chars_dupe_7grams": 0.02175066, "qsc_code_frac_chars_dupe_8grams": 0.02175066, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01324201, "qsc_code_frac_chars_whitespace": 0.14653157, "qsc_code_size_file_byte": 5132.0, "qsc_code_num_lines": 157.0, "qsc_code_num_chars_line_max": 117.0, "qsc_code_num_chars_line_mean": 32.68789809, "qsc_code_frac_chars_alphabet": 0.84748858, "qsc_code_frac_chars_comments": 0.20557288, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.03738318, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00171695, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00196223, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07476636, "qsc_codejava_score_lines_no_logic": 0.28037383, "qsc_codejava_frac_words_no_modifier": 0.77777778, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/journal/AlchemyPage.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.journal;
import com.shatteredpixel.shatteredpixeldungeon.items.journal.DocumentPage;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
public class AlchemyPage extends DocumentPage {
{
image = ItemSpriteSheet.ALCH_PAGE;
}
@Override
public Document document() {
return Document.ALCHEMY_GUIDE;
}
@Override
public String desc() {
return Messages.get(this, "desc", document().pageTitle(page()));
}
}
| 1,411 | AlchemyPage | java | en | java | code | {"qsc_code_num_words": 181, "qsc_code_num_chars": 1411.0, "qsc_code_mean_word_length": 5.97237569, "qsc_code_frac_words_unique": 0.57458564, "qsc_code_frac_chars_top_2grams": 0.0786309, "qsc_code_frac_chars_top_3grams": 0.17576318, "qsc_code_frac_chars_top_4grams": 0.16281221, "qsc_code_frac_chars_dupe_5grams": 0.16836263, "qsc_code_frac_chars_dupe_6grams": 0.05180389, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01424979, "qsc_code_frac_chars_whitespace": 0.15450035, "qsc_code_size_file_byte": 1411.0, "qsc_code_num_lines": 44.0, "qsc_code_num_chars_line_max": 76.0, "qsc_code_num_chars_line_mean": 32.06818182, "qsc_code_frac_chars_alphabet": 0.89186924, "qsc_code_frac_chars_comments": 0.55279943, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11111111, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00633914, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.11111111, "qsc_codejava_score_lines_no_logic": 0.38888889, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/journal/DocumentPage.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.journal;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndJournal;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
public abstract class DocumentPage extends Item {
{
image = ItemSpriteSheet.MASTERY;
}
public abstract Document document();
private String page;
public void page( String page ){
this.page = page;
}
public String page(){
return page;
}
@Override
public final boolean doPickUp(Hero hero) {
GameScene.pickUpJournal(this, hero.pos);
GameScene.flashJournal();
if (document() == Document.ALCHEMY_GUIDE){
WndJournal.last_index = 1;
} else {
WndJournal.last_index = 0;
}
document().addPage(page);
Sample.INSTANCE.play( Assets.SND_ITEM );
hero.spendAndNext( TIME_TO_PICK_UP );
return true;
}
private static final String PAGE = "page";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put( PAGE, page() );
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
page = bundle.getString( PAGE );
}
}
| 2,314 | DocumentPage | java | en | java | code | {"qsc_code_num_words": 286, "qsc_code_num_chars": 2314.0, "qsc_code_mean_word_length": 6.11188811, "qsc_code_frac_words_unique": 0.5, "qsc_code_frac_chars_top_2grams": 0.04633867, "qsc_code_frac_chars_top_3grams": 0.17391304, "qsc_code_frac_chars_top_4grams": 0.17620137, "qsc_code_frac_chars_dupe_5grams": 0.07665904, "qsc_code_frac_chars_dupe_6grams": 0.03203661, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00969388, "qsc_code_frac_chars_whitespace": 0.15298185, "qsc_code_size_file_byte": 2314.0, "qsc_code_num_lines": 80.0, "qsc_code_num_chars_line_max": 73.0, "qsc_code_num_chars_line_mean": 28.925, "qsc_code_frac_chars_alphabet": 0.88214286, "qsc_code_frac_chars_comments": 0.3375108, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0625, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00260926, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08333333, "qsc_codejava_score_lines_no_logic": 0.35416667, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/_IOBluetoothUI.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"""
Provides a python interface to the Mac OSX IOBluetoothUI Framework classes,
through PyObjC.
For example:
>>> from lightblue import _IOBluetoothUI
>>> selector = _IOBluetoothUI.IOBluetoothDeviceSelectorController.deviceSelector()
>>> selector.runModal() # ask user to select a device
-1000
>>> for device in selector.getResults():
... print device.getName() # show name of selected device
...
Nokia 6600
>>>
See http://developer.apple.com/documentation/DeviceDrivers/Reference/IOBluetoothUI/index.html
for Apple's IOBluetoothUI documentation.
See http://pyobjc.sourceforge.net for details on how to access Objective-C
classes through PyObjC.
"""
import objc
try:
# mac os 10.5 loads frameworks using bridgesupport metadata
__bundle__ = objc.initFrameworkWrapper("IOBluetoothUI",
frameworkIdentifier="com.apple.IOBluetoothUI",
frameworkPath=objc.pathForFramework(
"/System/Library/Frameworks/IOBluetoothUI.framework"),
globals=globals())
except (AttributeError, ValueError):
# earlier versions use loadBundle() and setSignatureForSelector()
objc.loadBundle("IOBluetoothUI", globals(),
bundle_path=objc.pathForFramework(u'/System/Library/Frameworks/IOBluetoothUI.framework'))
del objc
| 2,076 | _IOBluetoothUI | py | en | python | code | {"qsc_code_num_words": 249, "qsc_code_num_chars": 2076.0, "qsc_code_mean_word_length": 5.97188755, "qsc_code_frac_words_unique": 0.60240964, "qsc_code_frac_chars_top_2grams": 0.01008742, "qsc_code_frac_chars_top_3grams": 0.0262273, "qsc_code_frac_chars_top_4grams": 0.03833221, "qsc_code_frac_chars_dupe_5grams": 0.11566913, "qsc_code_frac_chars_dupe_6grams": 0.03765972, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00960961, "qsc_code_frac_chars_whitespace": 0.19797688, "qsc_code_size_file_byte": 2076.0, "qsc_code_num_lines": 57.0, "qsc_code_num_chars_line_max": 97.0, "qsc_code_num_chars_line_mean": 36.42105263, "qsc_code_frac_chars_alphabet": 0.88348348, "qsc_code_frac_chars_comments": 0.72591522, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.27954972, "qsc_code_frac_chars_long_word_length": 0.23076923, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.09090909, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.09090909, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/_lightblue.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
# Mac OS X main module implementation.
import types
import warnings
import Foundation
import AppKit
import objc
import _IOBluetooth
import _LightAquaBlue
import _lightbluecommon
import _macutil
import _bluetoothsockets
# public attributes
__all__ = ("finddevices", "findservices", "finddevicename",
"selectdevice", "selectservice",
"gethostaddr", "gethostclass",
"socket",
"advertise", "stopadvertise")
# details of advertised services
__advertised = {}
def finddevices(getnames=True, length=10):
inquiry = _SyncDeviceInquiry()
inquiry.run(getnames, length)
devices = inquiry.getfounddevices()
return devices
def findservices(addr=None, name=None, servicetype=None):
if servicetype not in (_lightbluecommon.RFCOMM, _lightbluecommon.OBEX, None):
raise ValueError("servicetype must be RFCOMM, OBEX or None, was %s" % \
servicetype)
if addr is None:
try:
founddevices = finddevices()
except _lightbluecommon.BluetoothError, e:
msg = "findservices() failed, " +\
"error while finding devices: " + str(e)
raise _lightbluecommon.BluetoothError(msg)
#print founddevices
addresses = [dev[0] for dev in founddevices]
else:
addresses = [addr]
services = []
for devaddr in addresses:
iobtdevice = _IOBluetooth.IOBluetoothDevice.withAddress_(
_macutil.createbtdevaddr(devaddr))
try:
lastseen = iobtdevice.getLastServicesUpdate()
if lastseen is None or lastseen.timeIntervalSinceNow() < -2:
# perform SDP query to update known services.
# wait at least a few seconds between service discovery cos
# sometimes it doesn't work if doing updates too often.
# In future should have option to not do updates.
serviceupdater = _SDPQueryRunner.alloc().init()
try:
serviceupdater.query(iobtdevice) # blocks until updated
except _lightbluecommon.BluetoothError, e:
msg = "findservices() couldn't get services for %s: %s" % \
(iobtdevice.getNameOrAddress(), str(e))
warnings.warn(msg)
# or should I use cached services instead of warning?
# but sometimes the cached ones are totally wrong.
# if searching for RFCOMM, exclude OBEX services
if servicetype == _lightbluecommon.RFCOMM:
uuidbad = _macutil.PROTO_UUIDS.get(_lightbluecommon.OBEX)
else:
uuidbad = None
filtered = _searchservices(iobtdevice, name=name,
uuid=_macutil.PROTO_UUIDS.get(servicetype),
uuidbad=uuidbad)
#print "unfiltered:", iobtdevice.getServices()
services.extend([_getservicetuple(s) for s in filtered])
finally:
# close baseband connection (not sure if this is necessary, but
# sometimes the transport connection seems to stay open?)
iobtdevice.closeConnection()
return services
def finddevicename(address, usecache=True):
if not _lightbluecommon._isbtaddr(address):
raise TypeError("%s is not a valid bluetooth address" % str(address))
if address == gethostaddr():
return _gethostname()
device = _IOBluetooth.IOBluetoothDevice.withAddress_(
_macutil.createbtdevaddr(address))
if usecache:
name = device.getName()
if name is not None:
return name
# do name request with timeout of 10 seconds
result = device.remoteNameRequest_withPageTimeout_(None, 10000)
if result == _macutil.kIOReturnSuccess:
return device.getName()
raise _lightbluecommon.BluetoothError(
"Could not find device name for %s" % address)
### local device ###
def gethostaddr():
addr = _LightAquaBlue.BBLocalDevice.getAddressString()
if addr is not None:
# PyObjC returns all strings as unicode, but the address doesn't need
# to be unicode cos it's just hex values
return _macutil.formatdevaddr(addr)
raise _lightbluecommon.BluetoothError("Cannot read local device address")
def gethostclass():
cod = _LightAquaBlue.BBLocalDevice.getClassOfDevice()
if cod != -1:
return int(cod)
raise _lightbluecommon.BluetoothError("Cannot read local device class")
def _gethostname():
name = _LightAquaBlue.BBLocalDevice.getName()
if name is not None:
return name
raise _lightbluecommon.BluetoothError("Cannot read local device name")
### socket ###
def socket(proto=_lightbluecommon.RFCOMM):
return _bluetoothsockets._getsocketobject(proto)
### advertising services ###
def advertise(name, sock, servicetype):
if not isinstance(name, types.StringTypes):
raise TypeError("name must be string, was %s" % \
type(name))
# raises exception if socket is not bound
boundchannelID = sock._getport()
# advertise the service
if servicetype == _lightbluecommon.RFCOMM:
try:
result, finalchannelID, servicerecordhandle = _LightAquaBlue.BBServiceAdvertiser.addRFCOMMServiceDictionary_withName_UUID_channelID_serviceRecordHandle_(
_LightAquaBlue.BBServiceAdvertiser.serialPortProfileDictionary(),
name,
None, None, None)
except:
result, finalchannelID, servicerecordhandle = _LightAquaBlue.BBServiceAdvertiser.addRFCOMMServiceDictionary_withName_UUID_channelID_serviceRecordHandle_(
_LightAquaBlue.BBServiceAdvertiser.serialPortProfileDictionary(),
name,
None)
elif servicetype == _lightbluecommon.OBEX:
try:
result, finalchannelID, servicerecordhandle = _LightAquaBlue.BBServiceAdvertiser.addRFCOMMServiceDictionary_withName_UUID_channelID_serviceRecordHandle_(
_LightAquaBlue.BBServiceAdvertiser.objectPushProfileDictionary(),
name,
None, None, None)
except:
result, finalchannelID, servicerecordhandle = _LightAquaBlue.BBServiceAdvertiser.addRFCOMMServiceDictionary_withName_UUID_channelID_serviceRecordHandle_(
_LightAquaBlue.BBServiceAdvertiser.objectPushProfileDictionary(),
name,
None)
else:
raise ValueError("servicetype must be either RFCOMM or OBEX")
if result != _macutil.kIOReturnSuccess:
raise _lightbluecommon.BluetoothError(
result, "Error advertising service")
if boundchannelID != finalchannelID:
msg = "socket bound to unavailable channel (%d), " % boundchannelID +\
"use channel value of 0 to bind to dynamically assigned channel"
raise _lightbluecommon.BluetoothError(msg)
# note service record handle, so that the service can be stopped later
__advertised[id(sock)] = servicerecordhandle
def stopadvertise(sock):
if sock is None:
raise TypeError("Given socket is None")
servicerecordhandle = __advertised.get(id(sock))
if servicerecordhandle is None:
raise _lightbluecommon.BluetoothError("no service advertised")
result = _LightAquaBlue.BBServiceAdvertiser.removeService_(servicerecordhandle)
if result != _macutil.kIOReturnSuccess:
raise _lightbluecommon.BluetoothError(
result, "Error stopping advertising of service")
### GUI ###
def selectdevice():
import _IOBluetoothUI
gui = _IOBluetoothUI.IOBluetoothDeviceSelectorController.deviceSelector()
# try to bring GUI to foreground by setting it as floating panel
# (if this is called from pyobjc app, it would automatically be in foreground)
try:
gui.window().setFloatingPanel_(True)
except:
pass
# show the window and wait for user's selection
response = gui.runModal() # problems here if transferring a lot of data??
if response == AppKit.NSRunStoppedResponse:
results = gui.getResults()
if len(results) > 0: # should always be > 0, but check anyway
devinfo = _getdevicetuple(results[0])
# sometimes the baseband connection stays open which causes
# problems with connections w so close it here, see if this fixes
# it
dev = _IOBluetooth.IOBluetoothDevice.withAddress_(
_macutil.createbtdevaddr(devinfo[0]))
if dev.isConnected():
dev.closeConnection()
return devinfo
# user cancelled selection
return None
def selectservice():
import _IOBluetoothUI
gui = _IOBluetoothUI.IOBluetoothServiceBrowserController.serviceBrowserController_(
_macutil.kIOBluetoothServiceBrowserControllerOptionsNone)
# try to bring GUI to foreground by setting it as floating panel
# (if this is called from pyobjc app, it would automatically be in foreground)
try:
gui.window().setFloatingPanel_(True)
except:
pass
# show the window and wait for user's selection
response = gui.runModal()
if response == AppKit.NSRunStoppedResponse:
results = gui.getResults()
if len(results) > 0: # should always be > 0, but check anyway
serviceinfo = _getservicetuple(results[0])
# sometimes the baseband connection stays open which causes
# problems with connections ... so close it here, see if this fixes
# it
dev = _IOBluetooth.IOBluetoothDevice.deviceWithAddressString_(serviceinfo[0])
if dev.isConnected():
dev.closeConnection()
return serviceinfo
# user cancelled selection
return None
### classes ###
class _SDPQueryRunner(Foundation.NSObject):
"""
Convenience class for performing a synchronous or asynchronous SDP query
on an IOBluetoothDevice.
"""
def query(self, device, timeout=10.0):
# do SDP query
err = device.performSDPQuery_(self)
if err != _macutil.kIOReturnSuccess:
raise _lightbluecommon.BluetoothError(err, self._errmsg(device))
# performSDPQuery_ is async, so block-wait
self._queryresult = None
if not _macutil.waituntil(lambda: self._queryresult is not None,
timeout):
raise _lightbluecommon.BluetoothError(
"Timed out getting services for %s" % \
device.getNameOrAddress())
# query is now complete
if self._queryresult != _macutil.kIOReturnSuccess:
raise _lightbluecommon.BluetoothError(
self._queryresult, self._errmsg(device))
def sdpQueryComplete_status_(self, device, status):
# can't raise exception during a callback, so just keep the err value
self._queryresult = status
_macutil.interruptwait()
sdpQueryComplete_status_ = objc.selector(
sdpQueryComplete_status_, signature="v@:@i") # accept object, int
def _errmsg(self, device):
return "Error getting services for %s" % device.getNameOrAddress()
class _SyncDeviceInquiry(object):
def __init__(self):
super(_SyncDeviceInquiry, self).__init__()
self._inquiry = _AsyncDeviceInquiry.alloc().init()
self._inquiry.cb_completed = self._inquirycomplete
self._inquiring = False
def run(self, getnames, duration):
if self._inquiring:
raise _lightbluecommon.BluetoothError(
"Another inquiry in progress")
# set inquiry attributes
self._inquiry.updatenames = getnames
self._inquiry.length = duration
# start the inquiry
err = self._inquiry.start()
if err != _macutil.kIOReturnSuccess:
raise _lightbluecommon.BluetoothError(
err, "Error starting device inquiry")
# if error occurs during inquiry, set _inquiryerr to the error code
self._inquiryerr = _macutil.kIOReturnSuccess
# wait until the inquiry is complete
self._inquiring = True
_macutil.waituntil(lambda: not self._inquiring)
# if error occured during inquiry, raise exception
if self._inquiryerr != _macutil.kIOReturnSuccess:
raise _lightbluecommon.BluetoothError(self._inquiryerr,
"Error during device inquiry")
def getfounddevices(self):
# return as list of device-info tuples
return [_getdevicetuple(device) for device in \
self._inquiry.getfounddevices()]
def _inquirycomplete(self, err, aborted):
if err != 188: # no devices found
self._inquiryerr = err
self._inquiring = False
_macutil.interruptwait()
def __del__(self):
self._inquiry.__del__()
super(_SyncDeviceInquiry, self).__del__()
# Wrapper around IOBluetoothDeviceInquiry, with python callbacks that you can
# set to receive callbacks when the inquiry is started or stopped, or when it
# finds a device.
#
# This discovery doesn't block, so it could be used in a PyObjC application
# that is running an event loop.
#
# Properties:
# - 'length': the inquiry length (seconds)
# - 'updatenames': whether to update device names during the inquiry
# (i.e. perform remote name requests, which will take a little longer)
#
class _AsyncDeviceInquiry(Foundation.NSObject):
# NSObject init, not python __init__
def init(self):
try:
attr = _IOBluetooth.IOBluetoothDeviceInquiry
except AttributeError:
raise ImportError("Cannot find IOBluetoothDeviceInquiry class " +\
"to perform device discovery. This class was introduced in " +\
"Mac OS X 10.4, are you running an earlier version?")
self = super(_AsyncDeviceInquiry, self).init()
self._inquiry = \
_IOBluetooth.IOBluetoothDeviceInquiry.inquiryWithDelegate_(self)
# callbacks
self.cb_started = None
self.cb_completed = None
self.cb_founddevice = None
return self
# length property
def _setlength(self, length):
self._inquiry.setInquiryLength_(length)
length = property(
lambda self: self._inquiry.inquiryLength(),
_setlength)
# updatenames property
def _setupdatenames(self, update):
self._inquiry.setUpdateNewDeviceNames_(update)
updatenames = property(
lambda self: self._inquiry.updateNewDeviceNames(),
_setupdatenames)
# returns error code
def start(self):
return self._inquiry.start()
# returns error code
def stop(self):
return self._inquiry.stop()
# returns list of IOBluetoothDevice objects
def getfounddevices(self):
return self._inquiry.foundDevices()
def __del__(self):
super(_AsyncDeviceInquiry, self).dealloc()
#
# delegate methods follow (these are called by the internal
# IOBluetoothDeviceInquiry object when inquiry events occur)
#
# - (void)deviceInquiryDeviceFound:(IOBluetoothDeviceInquiry*)sender
# device:(IOBluetoothDevice*)device;
def deviceInquiryDeviceFound_device_(self, inquiry, device):
if self.cb_founddevice:
self.cb_founddevice(device)
deviceInquiryDeviceFound_device_ = objc.selector(
deviceInquiryDeviceFound_device_, signature="v@:@@")
# - (void)deviceInquiryComplete:error:aborted;
def deviceInquiryComplete_error_aborted_(self, inquiry, err, aborted):
if self.cb_completed:
self.cb_completed(err, aborted)
deviceInquiryComplete_error_aborted_ = objc.selector(
deviceInquiryComplete_error_aborted_, signature="v@:@iB")
# - (void)deviceInquiryStarted:(IOBluetoothDeviceInquiry*)sender;
def deviceInquiryStarted_(self, inquiry):
if self.cb_started:
self.cb_started()
# - (void)deviceInquiryDeviceNameUpdated:device:devicesRemaining:
def deviceInquiryDeviceNameUpdated_device_devicesRemaining_(self, sender,
device,
devicesRemaining):
pass
# - (void)deviceInquiryUpdatingDeviceNamesStarted:devicesRemaining:
def deviceInquiryUpdatingDeviceNamesStarted_devicesRemaining_(self, sender,
devicesRemaining):
pass
### utility methods ###
def _searchservices(device, name=None, uuid=None, uuidbad=None):
"""
Searches the given IOBluetoothDevice using the specified parameters.
Returns an empty list if the device has no services.
uuid should be IOBluetoothSDPUUID object.
"""
if not isinstance(device, _IOBluetooth.IOBluetoothDevice):
raise ValueError("device must be IOBluetoothDevice, was %s" % \
type(device))
services = []
allservices = device.getServices()
if uuid:
gooduuids = (uuid, )
else:
gooduuids = ()
if uuidbad:
baduuids = (uuidbad, )
else:
baduuids = ()
if allservices is not None:
for s in allservices:
if gooduuids and not s.hasServiceFromArray_(gooduuids):
continue
if baduuids and s.hasServiceFromArray_(baduuids):
continue
if name is None or s.getServiceName() == name:
services.append(s)
return services
def _getdevicetuple(iobtdevice):
"""
Returns an (addr, name, COD) device tuple from a IOBluetoothDevice object.
"""
addr = _macutil.formatdevaddr(iobtdevice.getAddressString())
name = iobtdevice.getName()
cod = iobtdevice.getClassOfDevice()
return (addr, name, cod)
def _getservicetuple(servicerecord):
"""
Returns a (device-addr, service-channel, service-name) tuple from the given
IOBluetoothSDPServiceRecord.
"""
addr = _macutil.formatdevaddr(servicerecord.getDevice().getAddressString())
name = servicerecord.getServiceName()
try:
result, channel = servicerecord.getRFCOMMChannelID_(None) # pyobjc 2.0
except TypeError:
result, channel = servicerecord.getRFCOMMChannelID_()
if result != _macutil.kIOReturnSuccess:
try:
result, channel = servicerecord.getL2CAPPSM_(None) # pyobjc 2.0
except:
result, channel = servicerecord.getL2CAPPSM_()
if result != _macutil.kIOReturnSuccess:
channel = None
return (addr, channel, name)
| 20,312 | _lightblue | py | en | python | code | {"qsc_code_num_words": 1890, "qsc_code_num_chars": 20312.0, "qsc_code_mean_word_length": 6.67619048, "qsc_code_frac_words_unique": 0.25238095, "qsc_code_frac_chars_top_2grams": 0.01569187, "qsc_code_frac_chars_top_3grams": 0.04041845, "qsc_code_frac_chars_top_4grams": 0.02044698, "qsc_code_frac_chars_dupe_5grams": 0.24615628, "qsc_code_frac_chars_dupe_6grams": 0.21421778, "qsc_code_frac_chars_dupe_7grams": 0.18552861, "qsc_code_frac_chars_dupe_8grams": 0.1659534, "qsc_code_frac_chars_dupe_9grams": 0.15057854, "qsc_code_frac_chars_dupe_10grams": 0.13853226, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00286453, "qsc_code_frac_chars_whitespace": 0.29534265, "qsc_code_size_file_byte": 20312.0, "qsc_code_num_lines": 550.0, "qsc_code_num_chars_line_max": 166.0, "qsc_code_num_chars_line_mean": 36.93090909, "qsc_code_frac_chars_alphabet": 0.87871166, "qsc_code_frac_chars_comments": 0.20140803, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.29754601, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.06720637, "qsc_code_frac_chars_long_word_length": 0.00154202, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 0.0, "qsc_codepython_frac_lines_func_ratio": null, "qsc_codepython_cate_var_zero": null, "qsc_codepython_frac_lines_pass": 0.01226994, "qsc_codepython_frac_lines_import": 0.0398773, "qsc_codepython_frac_lines_simplefunc": null, "qsc_codepython_score_lines_no_logic": null, "qsc_codepython_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 1, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/series60/_lightblueutil/panic.h | // -*- symbian-c++ -*-
//
// panic.h
//
// Copyright 2004 Helsinki Institute for Information Technology (HIIT)
// and the authors. All rights reserved.
//
// Authors: Tero Hasu <tero.hasu@hut.fi>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef __PANIC_H__
#define __PANIC_H__
enum TAoSocketPanicCodes
{
EPanicAssertionFailed = 0,
EPanicSocketAlreadyOpen,
EPanicSocketNotOpen,
EPanicRequestAlreadyPending,
EPanicExceptionInCallback,
EPanicOutOfMemory,
EPanicSessionDoesNotExist,
EPanicSessionAlreadyExists,
EPanicAccessWithWrongThread,
EPanicConfigBeforeListen,
EPanicAcceptBeforeListen,
EPanicUseBeforeInit,
EPanicNextBeforeFirst,
EPanicWrongTransportMode,
EPanicSocketServNotSet,
EPanicArgumentError
};
void AoSocketPanic(TInt aReason);
void AssertFail();
void AssertNonNull(void* aPtr);
void AssertNull(void* aPtr);
#endif // __PANIC_H__
| 1,911 | panic | h | en | c | code | {"qsc_code_num_words": 230, "qsc_code_num_chars": 1911.0, "qsc_code_mean_word_length": 6.37826087, "qsc_code_frac_words_unique": 0.59130435, "qsc_code_frac_chars_top_2grams": 0.05998637, "qsc_code_frac_chars_top_3grams": 0.01772324, "qsc_code_frac_chars_top_4grams": 0.0, "qsc_code_frac_chars_dupe_5grams": 0.0, "qsc_code_frac_chars_dupe_6grams": 0.0, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00306937, "qsc_code_frac_chars_whitespace": 0.14756672, "qsc_code_size_file_byte": 1911.0, "qsc_code_num_lines": 60.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 31.85, "qsc_code_frac_chars_alphabet": 0.89748312, "qsc_code_frac_chars_comments": 0.67922554, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.15384615, "qsc_codec_frac_lines_func_ratio": 0.15384615, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 1.0, "qsc_codec_score_lines_no_logic": 0.15384615, "qsc_codec_frac_lines_print": 0.0, "qsc_codec_frac_lines_preprocessor_directives": null} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 0, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/journal/GuidePage.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.journal;
import com.shatteredpixel.shatteredpixeldungeon.journal.Document;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
public class GuidePage extends DocumentPage {
{
image = ItemSpriteSheet.GUIDE_PAGE;
}
@Override
public Document document() {
return Document.ADVENTURERS_GUIDE;
}
@Override
public String desc() {
return Messages.get(this, "desc", document().pageTitle(page()));
}
}
| 1,338 | GuidePage | java | en | java | code | {"qsc_code_num_words": 174, "qsc_code_num_chars": 1338.0, "qsc_code_mean_word_length": 5.83908046, "qsc_code_frac_words_unique": 0.59195402, "qsc_code_frac_chars_top_2grams": 0.06692913, "qsc_code_frac_chars_top_3grams": 0.1496063, "qsc_code_frac_chars_top_4grams": 0.05610236, "qsc_code_frac_chars_dupe_5grams": 0.08070866, "qsc_code_frac_chars_dupe_6grams": 0.05511811, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01515152, "qsc_code_frac_chars_whitespace": 0.16143498, "qsc_code_size_file_byte": 1338.0, "qsc_code_num_lines": 43.0, "qsc_code_num_chars_line_max": 73.0, "qsc_code_num_chars_line_mean": 31.11627907, "qsc_code_frac_chars_alphabet": 0.89037433, "qsc_code_frac_chars_comments": 0.58370703, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.11764706, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00718133, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.11764706, "qsc_codejava_score_lines_no_logic": 0.35294118, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | COPYING | GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
| 35,147 | COPYING | en | text | text | {"qsc_doc_frac_chars_curly_bracket": 0.0, "qsc_doc_frac_words_redpajama_stop": 0.43654822, "qsc_doc_num_sentences": 218.0, "qsc_doc_num_words": 5700, "qsc_doc_num_chars": 35147.0, "qsc_doc_num_lines": 674.0, "qsc_doc_mean_word_length": 4.87719298, "qsc_doc_frac_words_full_bracket": 0.0, "qsc_doc_frac_lines_end_with_readmore": 0.0, "qsc_doc_frac_lines_start_with_bullet": 0.0, "qsc_doc_frac_words_unique": 0.18017544, "qsc_doc_entropy_unigram": 5.57884301, "qsc_doc_frac_words_all_caps": 0.0396862, "qsc_doc_frac_lines_dupe_lines": 0.0, "qsc_doc_frac_chars_dupe_lines": 0.0, "qsc_doc_frac_chars_top_2grams": 0.0131295, "qsc_doc_frac_chars_top_3grams": 0.0094964, "qsc_doc_frac_chars_top_4grams": 0.0107554, "qsc_doc_frac_chars_dupe_5grams": 0.12410072, "qsc_doc_frac_chars_dupe_6grams": 0.07964029, "qsc_doc_frac_chars_dupe_7grams": 0.04402878, "qsc_doc_frac_chars_dupe_8grams": 0.03345324, "qsc_doc_frac_chars_dupe_9grams": 0.0223741, "qsc_doc_frac_chars_dupe_10grams": 0.01510791, "qsc_doc_frac_chars_replacement_symbols": 0.0, "qsc_doc_cate_code_related_file_name": 0.0, "qsc_doc_num_chars_sentence_length_mean": 38.35946249, "qsc_doc_frac_chars_hyperlink_html_tag": 0.00711298, "qsc_doc_frac_chars_alphabet": 0.96738599, "qsc_doc_frac_chars_digital": 0.00335219, "qsc_doc_frac_chars_whitespace": 0.18519362, "qsc_doc_frac_chars_hex_words": 0.0} | 1 | {"qsc_doc_frac_chars_replacement_symbols": 0, "qsc_doc_entropy_unigram": 0, "qsc_doc_frac_chars_top_2grams": 0, "qsc_doc_frac_chars_top_3grams": 0, "qsc_doc_frac_chars_top_4grams": 0, "qsc_doc_frac_chars_dupe_5grams": 0, "qsc_doc_frac_chars_dupe_6grams": 0, "qsc_doc_frac_chars_dupe_7grams": 0, "qsc_doc_frac_chars_dupe_8grams": 0, "qsc_doc_frac_chars_dupe_9grams": 0, "qsc_doc_frac_chars_dupe_10grams": 0, "qsc_doc_frac_chars_dupe_lines": 0, "qsc_doc_frac_lines_dupe_lines": 0, "qsc_doc_frac_lines_end_with_readmore": 0, "qsc_doc_frac_lines_start_with_bullet": 0, "qsc_doc_frac_words_all_caps": 0, "qsc_doc_mean_word_length": 0, "qsc_doc_num_chars": 0, "qsc_doc_num_lines": 0, "qsc_doc_num_sentences": 0, "qsc_doc_num_words": 0, "qsc_doc_frac_chars_hex_words": 0, "qsc_doc_frac_chars_hyperlink_html_tag": 0, "qsc_doc_frac_chars_alphabet": 0, "qsc_doc_frac_chars_digital": 0, "qsc_doc_frac_chars_whitespace": 0} | |
0-1-0/lightblue-0.4 | PKG-INFO | Metadata-Version: 1.0
Name: lightblue
Version: 0.4
Summary: Cross-platform Python Bluetooth library for Mac OS X, GNU/Linux and Python for Series 60.
Home-page: http://lightblue.sourceforge.net
Author: Bea Lam
Author-email: blammit@gmail.com
License: GPL
Description: LightBlue is a cross-platform Python Bluetooth library for Mac OS X, GNU/Linux and Python for Series 60. It provides support for device and service discovery (with and without end-user GUIs), a standard socket interface for RFCOMM sockets, sending and receiving of files over OBEX, advertising of RFCOMM and OBEX services, and access to local device information.
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: License :: OSI Approved :: GNU General Public License v3
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Networking
Classifier: Topic :: Communications
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Other OS
| 1,191 | PKG-INFO | en | unknown | unknown | {} | 0 | {} | |
0-1-0/lightblue-0.4 | setup.py | # On Python for Series 60, use the SIS files instead.
from distutils.core import setup, Extension
import sys
LINUX = sys.platform.startswith("linux")
MAC = sys.platform.startswith("darwin")
def getpackagedir():
if MAC:
return "src/mac"
elif LINUX:
return "src/linux"
else:
raise Exception("Unsupported platform")
def getextensions():
if LINUX:
linux_ext = Extension("_lightblueutil",
libraries=["bluetooth"], # C libraries
sources=["src/linux/lightblue_util.c"]
)
linux_obex_ext = Extension("_lightblueobex",
define_macros=[('LIGHTBLUE_DEBUG', '0')], # set to '1' to print debug messges
libraries=["bluetooth", "openobex"], # C libraries
sources=["src/linux/lightblueobex_client.c",
"src/linux/lightblueobex_server.c",
"src/linux/lightblueobex_main.c"],
)
return [linux_ext, linux_obex_ext]
return []
# install the main library
setup(name="lightblue",
version="0.4",
author="Bea Lam",
author_email="blammit@gmail.com",
url="http://lightblue.sourceforge.net",
description="Cross-platform Python Bluetooth library for Mac OS X, GNU/Linux and Python for Series 60.",
long_description="LightBlue is a cross-platform Python Bluetooth library for Mac OS X, GNU/Linux and Python for Series 60. It provides support for device and service discovery (with and without end-user GUIs), a standard socket interface for RFCOMM sockets, sending and receiving of files over OBEX, advertising of RFCOMM and OBEX services, and access to local device information.",
license="GPL",
packages=["lightblue"],
package_dir={"lightblue":getpackagedir()},
ext_modules=getextensions(),
classifiers = [ "Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License (GPL)",
"License :: OSI Approved :: GNU General Public License v3",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries",
"Topic :: System :: Networking",
"Topic :: Communications",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
"Operating System :: Other OS" ]
)
# On Mac, install LightAquaBlue framework
# if you want to install the framework somewhere other than /Library/Frameworks
# make sure the path is also changed in LightAquaBlue.py (in src/mac)
if MAC:
if "install" in sys.argv:
import os
os.chdir("src/mac/LightAquaBlue")
os.system("xcodebuild install -arch '$(NATIVE_ARCH_ACTUAL)' -target LightAquaBlue -configuration Release DSTROOT=/ INSTALL_PATH=/Library/Frameworks DEPLOYMENT_LOCATION=YES")
| 2,821 | setup | py | en | python | code | {"qsc_code_num_words": 333, "qsc_code_num_chars": 2821.0, "qsc_code_mean_word_length": 5.55855856, "qsc_code_frac_words_unique": 0.48948949, "qsc_code_frac_chars_top_2grams": 0.02160994, "qsc_code_frac_chars_top_3grams": 0.02431118, "qsc_code_frac_chars_top_4grams": 0.02755267, "qsc_code_frac_chars_dupe_5grams": 0.14910859, "qsc_code_frac_chars_dupe_6grams": 0.12209616, "qsc_code_frac_chars_dupe_7grams": 0.12209616, "qsc_code_frac_chars_dupe_8grams": 0.07779579, "qsc_code_frac_chars_dupe_9grams": 0.07779579, "qsc_code_frac_chars_dupe_10grams": 0.07779579, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00550459, "qsc_code_frac_chars_whitespace": 0.22722439, "qsc_code_size_file_byte": 2821.0, "qsc_code_num_lines": 66.0, "qsc_code_num_chars_line_max": 387.0, "qsc_code_num_chars_line_mean": 42.74242424, "qsc_code_frac_chars_alphabet": 0.84357798, "qsc_code_frac_chars_comments": 0.11343495, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.03703704, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.03703704, "qsc_code_frac_chars_string_length": 0.54735152, "qsc_code_frac_chars_long_word_length": 0.08788122, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.03703704, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.05555556, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.16666667, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfTerror.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.Flare;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
public class ScrollOfTerror extends Scroll {
{
initials = 9;
}
@Override
public void doRead() {
new Flare( 5, 32 ).color( 0xFF0000, true ).show( curUser.sprite, 2f );
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
int count = 0;
Mob affected = null;
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (mob.alignment != Char.Alignment.ALLY && Dungeon.level.heroFOV[mob.pos]) {
Buff.affect( mob, Terror.class, 20f ).object = curUser.id();
if (mob.buff(Terror.class) != null){
count++;
affected = mob;
}
}
}
switch (count) {
case 0:
GLog.i( Messages.get(this, "none") );
break;
case 1:
GLog.i( Messages.get(this, "one", affected.name) );
break;
default:
GLog.i( Messages.get(this, "many") );
}
setKnown();
readAnimation();
}
@Override
public void empoweredRead() {
doRead();
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (Dungeon.level.heroFOV[mob.pos]) {
Terror t = mob.buff(Terror.class);
if (t != null){
Buff.prolong(mob, Terror.class, 15f);
Buff.affect(mob, Paralysis.class, 5f);
}
}
}
}
@Override
public int price() {
return isKnown() ? 40 * quantity : super.price();
}
}
| 2,854 | ScrollOfTerror | java | en | java | code | {"qsc_code_num_words": 360, "qsc_code_num_chars": 2854.0, "qsc_code_mean_word_length": 5.70555556, "qsc_code_frac_words_unique": 0.46388889, "qsc_code_frac_chars_top_2grams": 0.0993184, "qsc_code_frac_chars_top_3grams": 0.22200584, "qsc_code_frac_chars_top_4grams": 0.23563778, "qsc_code_frac_chars_dupe_5grams": 0.28919182, "qsc_code_frac_chars_dupe_6grams": 0.17429406, "qsc_code_frac_chars_dupe_7grams": 0.0399221, "qsc_code_frac_chars_dupe_8grams": 0.0399221, "qsc_code_frac_chars_dupe_9grams": 0.0399221, "qsc_code_frac_chars_dupe_10grams": 0.0399221, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0163728, "qsc_code_frac_chars_whitespace": 0.16538192, "qsc_code_size_file_byte": 2854.0, "qsc_code_num_lines": 95.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 30.04210526, "qsc_code_frac_chars_alphabet": 0.84592779, "qsc_code_frac_chars_comments": 0.27365102, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.109375, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00530632, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00385914, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.078125, "qsc_codejava_score_lines_no_logic": 0.28125, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfLullaby.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Drowsy;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
public class ScrollOfLullaby extends Scroll {
{
initials = 1;
}
@Override
public void doRead() {
curUser.sprite.centerEmitter().start( Speck.factory( Speck.NOTE ), 0.3f, 5 );
Sample.INSTANCE.play( Assets.SND_LULLABY );
Invisibility.dispel();
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (Dungeon.level.heroFOV[mob.pos]) {
Buff.affect( mob, Drowsy.class );
mob.sprite.centerEmitter().start( Speck.factory( Speck.NOTE ), 0.3f, 5 );
}
}
Buff.affect( curUser, Drowsy.class );
GLog.i( Messages.get(this, "sooth") );
setKnown();
readAnimation();
}
@Override
public void empoweredRead() {
doRead();
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (Dungeon.level.heroFOV[mob.pos]) {
Buff drowsy = mob.buff(Drowsy.class);
if (drowsy != null) drowsy.act();
}
}
}
@Override
public int price() {
return isKnown() ? 40 * quantity : super.price();
}
}
| 2,416 | ScrollOfLullaby | java | en | java | code | {"qsc_code_num_words": 306, "qsc_code_num_chars": 2416.0, "qsc_code_mean_word_length": 5.82352941, "qsc_code_frac_words_unique": 0.47712418, "qsc_code_frac_chars_top_2grams": 0.09539843, "qsc_code_frac_chars_top_3grams": 0.21324355, "qsc_code_frac_chars_top_4grams": 0.22222222, "qsc_code_frac_chars_dupe_5grams": 0.30022447, "qsc_code_frac_chars_dupe_6grams": 0.25757576, "qsc_code_frac_chars_dupe_7grams": 0.1335578, "qsc_code_frac_chars_dupe_8grams": 0.1335578, "qsc_code_frac_chars_dupe_9grams": 0.1335578, "qsc_code_frac_chars_dupe_10grams": 0.1335578, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01367855, "qsc_code_frac_chars_whitespace": 0.15273179, "qsc_code_size_file_byte": 2416.0, "qsc_code_num_lines": 78.0, "qsc_code_num_chars_line_max": 80.0, "qsc_code_num_chars_line_mean": 30.97435897, "qsc_code_frac_chars_alphabet": 0.8568637, "qsc_code_frac_chars_comments": 0.32326159, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.15217391, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0030581, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08695652, "qsc_codejava_score_lines_no_logic": 0.32608696, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfMirrorImage.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.MirrorImage;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class ScrollOfMirrorImage extends Scroll {
{
initials = 3;
}
private static final int NIMAGES = 2;
@Override
public void doRead() {
int spawnedImages = spawnImages(curUser, NIMAGES);
if (spawnedImages > 0) {
setKnown();
}
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
readAnimation();
}
@Override
public void empoweredRead() {
//spawns 2 images right away, delays 3 of them, 5 total.
new DelayedImageSpawner(5 - spawnImages(curUser, 2), 1, 2).attachTo(curUser);
setKnown();
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
readAnimation();
}
//returns the number of images spawned
public static int spawnImages( Hero hero, int nImages ){
ArrayList<Integer> respawnPoints = new ArrayList<>();
for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) {
int p = hero.pos + PathFinder.NEIGHBOURS8[i];
if (Actor.findChar( p ) == null && Dungeon.level.passable[p]) {
respawnPoints.add( p );
}
}
int spawned = 0;
while (nImages > 0 && respawnPoints.size() > 0) {
int index = Random.index( respawnPoints );
MirrorImage mob = new MirrorImage();
mob.duplicate( hero );
GameScene.add( mob );
ScrollOfTeleportation.appear( mob, respawnPoints.get( index ) );
respawnPoints.remove( index );
nImages--;
spawned++;
}
return spawned;
}
public static class DelayedImageSpawner extends Buff{
public DelayedImageSpawner(){
this(NIMAGES, NIMAGES, 1);
}
public DelayedImageSpawner( int total, int perRound, float delay){
super();
totImages = total;
imPerRound = perRound;
this.delay = delay;
}
private int totImages;
private int imPerRound;
private float delay;
@Override
public boolean attachTo(Char target) {
if (super.attachTo(target)){
spend(delay);
return true;
} else {
return false;
}
}
@Override
public boolean act() {
int spawned = spawnImages((Hero)target, Math.min(totImages, imPerRound));
totImages -= spawned;
if (totImages <0){
detach();
} else {
spend( delay );
}
return true;
}
private static final String TOTAL = "images";
private static final String PER_ROUND = "per_round";
private static final String DELAY = "delay";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put( TOTAL, totImages );
bundle.put( PER_ROUND, imPerRound );
bundle.put( DELAY, delay );
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
totImages = bundle.getInt( TOTAL );
imPerRound = bundle.getInt( PER_ROUND );
delay = bundle.getFloat( DELAY );
}
}
@Override
public int price() {
return isKnown() ? 30 * quantity : super.price();
}
}
| 4,451 | ScrollOfMirrorImage | java | en | java | code | {"qsc_code_num_words": 515, "qsc_code_num_chars": 4451.0, "qsc_code_mean_word_length": 6.11262136, "qsc_code_frac_words_unique": 0.38834951, "qsc_code_frac_chars_top_2grams": 0.03716645, "qsc_code_frac_chars_top_3grams": 0.12071156, "qsc_code_frac_chars_top_4grams": 0.12579416, "qsc_code_frac_chars_dupe_5grams": 0.18678526, "qsc_code_frac_chars_dupe_6grams": 0.09720457, "qsc_code_frac_chars_dupe_7grams": 0.04447268, "qsc_code_frac_chars_dupe_8grams": 0.04447268, "qsc_code_frac_chars_dupe_9grams": 0.04447268, "qsc_code_frac_chars_dupe_10grams": 0.04447268, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01024363, "qsc_code_frac_chars_whitespace": 0.18849697, "qsc_code_size_file_byte": 4451.0, "qsc_code_num_lines": 171.0, "qsc_code_num_chars_line_max": 80.0, "qsc_code_num_chars_line_mean": 26.02923977, "qsc_code_frac_chars_alphabet": 0.86129568, "qsc_code_frac_chars_comments": 0.19658504, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.1826087, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00559284, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08695652, "qsc_codejava_score_lines_no_logic": 0.27826087, "qsc_codejava_frac_words_no_modifier": 0.72727273, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/scrolls/ScrollOfRage.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.scrolls;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Amok;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
public class ScrollOfRage extends Scroll {
{
initials = 5;
}
@Override
public void doRead() {
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
mob.beckon( curUser.pos );
if (mob.alignment != Char.Alignment.ALLY && Dungeon.level.heroFOV[mob.pos]) {
Buff.prolong(mob, Amok.class, 5f);
}
}
for (Heap heap : Dungeon.level.heaps.valueList()) {
if (heap.type == Heap.Type.MIMIC) {
Mimic m = Mimic.spawnAt( heap.pos, heap.items );
if (m != null) {
m.beckon( curUser.pos );
heap.destroy();
}
}
}
GLog.w( Messages.get(this, "roar") );
setKnown();
curUser.sprite.centerEmitter().start( Speck.factory( Speck.SCREAM ), 0.3f, 3 );
Sample.INSTANCE.play( Assets.SND_CHALLENGE );
Invisibility.dispel();
readAnimation();
}
@Override
public void empoweredRead() {
for (Mob mob : Dungeon.level.mobs.toArray( new Mob[0] )) {
if (Dungeon.level.heroFOV[mob.pos]) {
Buff.prolong(mob, Amok.class, 5f);
}
}
setKnown();
curUser.sprite.centerEmitter().start( Speck.factory( Speck.SCREAM ), 0.3f, 3 );
Sample.INSTANCE.play( Assets.SND_READ );
Invisibility.dispel();
readAnimation();
}
@Override
public int price() {
return isKnown() ? 40 * quantity : super.price();
}
}
| 2,926 | ScrollOfRage | java | en | java | code | {"qsc_code_num_words": 364, "qsc_code_num_chars": 2926.0, "qsc_code_mean_word_length": 5.88461538, "qsc_code_frac_words_unique": 0.43406593, "qsc_code_frac_chars_top_2grams": 0.1031746, "qsc_code_frac_chars_top_3grams": 0.23062558, "qsc_code_frac_chars_top_4grams": 0.2464986, "qsc_code_frac_chars_dupe_5grams": 0.40102708, "qsc_code_frac_chars_dupe_6grams": 0.32352941, "qsc_code_frac_chars_dupe_7grams": 0.16993464, "qsc_code_frac_chars_dupe_8grams": 0.16993464, "qsc_code_frac_chars_dupe_9grams": 0.16993464, "qsc_code_frac_chars_dupe_10grams": 0.16993464, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01210165, "qsc_code_frac_chars_whitespace": 0.15276828, "qsc_code_size_file_byte": 2926.0, "qsc_code_num_lines": 94.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 31.12765957, "qsc_code_frac_chars_alphabet": 0.85195643, "qsc_code_frac_chars_comments": 0.26691729, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.25, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0018648, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.06666667, "qsc_codejava_score_lines_no_logic": 0.3, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | doc/lightblue.obex.html | <html>
<head>
<title>module lightblue.obex</title>
<link rel='stylesheet' href='shortdoc.css' />
</head>
<body>
<div class='module'>
<h2 class='moduletitle'>module <span class='modulename'><a href='index.html'>lightblue</a>.obex</span></h2>
<pre class='doc'>Provides an OBEX client class and convenience functions for sending and
receiving files over OBEX.
This module also defines constants for response code values (without the final
bit set). For example:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>import</span> lightblue
<span class="interpreter">>>></span> lightblue.obex.OK
<span class='number'>32</span> <span class='comment'># the OK/Success response 0x20 (i.e. 0xA0 without the final bit)</span>
<span class="interpreter">>>></span> lightblue.obex.FORBIDDEN
<span class='number'>67</span> <span class='comment'># the Forbidden response 0x43 (i.e. 0xC3 without the final bit)</span></code></pre></pre><div id='classes' class='section'>
<h2 class='sectiontitle'>Classes & Types</h2>
<div class='class'>
<a href='lightblue.obex-OBEXClient.html'><h3 class='classtitle'>class <span class='classname'>OBEXClient</span> </h3>
</a>
<div class='doc'>An OBEX client class.</div>
</div>
<div class='class'>
<a href='lightblue.obex-OBEXResponse.html'><h3 class='classtitle'>class <span class='classname'>OBEXResponse</span> </h3>
</a>
<div class='doc'>Contains the OBEX response received from an OBEX server.</div>
</div>
<div class='class'>
<a href='lightblue.obex-OBEXError.html'><h3 class='classtitle'>exception <span class='classname'>OBEXError</span> <span class='superclasstitle'>(<tt>lightblue.BluetoothError</tt>)</span></h3>
</a>
<div class='doc'>Generic exception raised for OBEX-related errors.</div>
</div>
</div>
<div id='functions' class='section'>
<h2 class='sectiontitle'>Functions</h2>
<div id='functionlinks'>
<ul>
<li><a href='#sendfile'><strong>sendfile</strong>(<span class='sig'>address, channel, source</span>)
</a></li>
<li><a href='#recvfile'><strong>recvfile</strong>(<span class='sig'>sock, dest</span>)
</a></li>
</ul>
</div>
<a name='sendfile'></a><h4 class='functitle'>sendfile(<span class='sig'>address, channel, source</span>)
</h4>
<pre class='doc'> Sends a file to a remote device.
Raises lightblue.obex.OBEXError if an error occurred during the request, or
if the request was refused by the remote device.
Arguments:
- address: the address of the remote device
- channel: the RFCOMM channel of the remote OBEX service
- source: a filename or file-like object, containing the data to be
sent. If a file object is given, it must be opened for reading.
Note you can achieve the same thing using OBEXClient with something like
this:
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>import</span> lightblue
<span class="interpreter">>>></span> client = lightblue.obex.OBEXClient(address, channel)
<span class="interpreter">>>></span> client.connect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> putresponse = client.put({<span class='string'>"name"</span>: <span class='string'>"MyFile.txt"</span>}, file(<span class='string'>"MyFile.txt"</span>, <span class='string'>'rb'</span>))
<span class="interpreter">>>></span> client.disconnect()
<OBEXResponse reason=<span class='string'>'OK'</span> code=<span class='number'>0x20</span> (<span class='number'>0xa0</span>) headers={}>
<span class="interpreter">>>></span> <span class='keyword'>if</span> putresponse.code != lightblue.obex.OK:
... <span class='keyword'>raise</span> lightblue.obex.OBEXError(<span class='string'>"request denied"</span>)
<span class="interpreter">>>></span></code></pre></pre>
<a name='recvfile'></a><h4 class='functitle'>recvfile(<span class='sig'>sock, dest</span>)
</h4>
<pre class='doc'> Receives a file through an OBEX service.
Arguments:
- sock: the server socket on which the file is to be received. Note
this socket must *not* be listening. Also, an OBEX service should
have been advertised on this socket.
- dest: a filename or file-like object, to which the received data will
be written. If a filename is given, any existing file will be
overwritten. If a file object is given, it must be opened for writing.
For example, to receive a file and save it as "MyFile.txt":
<pre class='python'><code> <span class="interpreter">>>></span> <span class='keyword'>from</span> lightblue <span class='keyword'>import</span> *
<span class="interpreter">>>></span> s = socket()
<span class="interpreter">>>></span> s.bind((<span class='string'>""</span>, <span class='number'>0</span>))
<span class="interpreter">>>></span> advertise(<span class='string'>"My OBEX Service"</span>, s, OBEX)
<span class="interpreter">>>></span> obex.recvfile(s, <span class='string'>"MyFile.txt"</span>)</code></pre></pre>
</div>
<div id='variables' class='section'>
<h2 class='sectiontitle'>Data</h2>
<h4 class='variable'>CONTINUE = 16</h4>
<h4 class='variable'>OK = 32</h4>
<h4 class='variable'>CREATED = 33</h4>
<h4 class='variable'>ACCEPTED = 34</h4>
<h4 class='variable'>NON_AUTHORITATIVE_INFORMATION = 35</h4>
<h4 class='variable'>NO_CONTENT = 36</h4>
<h4 class='variable'>RESET_CONTENT = 37</h4>
<h4 class='variable'>PARTIAL_CONTENT = 38</h4>
<h4 class='variable'>MULTIPLE_CHOICES = 48</h4>
<h4 class='variable'>MOVED_PERMANENTLY = 49</h4>
<h4 class='variable'>MOVED_TEMPORARILY = 50</h4>
<h4 class='variable'>SEE_OTHER = 51</h4>
<h4 class='variable'>NOT_MODIFIED = 52</h4>
<h4 class='variable'>USE_PROXY = 53</h4>
<h4 class='variable'>BAD_REQUEST = 64</h4>
<h4 class='variable'>UNAUTHORIZED = 65</h4>
<h4 class='variable'>PAYMENT_REQUIRED = 66</h4>
<h4 class='variable'>FORBIDDEN = 67</h4>
<h4 class='variable'>NOT_FOUND = 68</h4>
<h4 class='variable'>METHOD_NOT_ALLOWED = 69</h4>
<h4 class='variable'>NOT_ACCEPTABLE = 70</h4>
<h4 class='variable'>PROXY_AUTHENTICATION_REQUIRED = 71</h4>
<h4 class='variable'>REQUEST_TIME_OUT = 72</h4>
<h4 class='variable'>CONFLICT = 73</h4>
<h4 class='variable'>GONE = 74</h4>
<h4 class='variable'>LENGTH_REQUIRED = 75</h4>
<h4 class='variable'>PRECONDITION_FAILED = 76</h4>
<h4 class='variable'>REQUESTED_ENTITY_TOO_LARGE = 77</h4>
<h4 class='variable'>REQUEST_URL_TOO_LARGE = 78</h4>
<h4 class='variable'>UNSUPPORTED_MEDIA_TYPE = 79</h4>
<h4 class='variable'>INTERNAL_SERVER_ERROR = 80</h4>
<h4 class='variable'>NOT_IMPLEMENTED = 81</h4>
<h4 class='variable'>BAD_GATEWAY = 82</h4>
<h4 class='variable'>SERVICE_UNAVAILABLE = 83</h4>
<h4 class='variable'>GATEWAY_TIMEOUT = 84</h4>
<h4 class='variable'>HTTP_VERSION_NOT_SUPPORTED = 85</h4>
<h4 class='variable'>DATABASE_FULL = 96</h4>
<h4 class='variable'>DATABASE_LOCKED = 97</h4>
</div>
</div>
</body></html> | 7,244 | lightblue.obex | html | en | html | code | {"qsc_code_num_words": 1054, "qsc_code_num_chars": 7244.0, "qsc_code_mean_word_length": 4.66129032, "qsc_code_frac_words_unique": 0.26185958, "qsc_code_frac_chars_top_2grams": 0.08976186, "qsc_code_frac_chars_top_3grams": 0.11601873, "qsc_code_frac_chars_top_4grams": 0.12802768, "qsc_code_frac_chars_dupe_5grams": 0.40647262, "qsc_code_frac_chars_dupe_6grams": 0.29452473, "qsc_code_frac_chars_dupe_7grams": 0.24648891, "qsc_code_frac_chars_dupe_8grams": 0.21941787, "qsc_code_frac_chars_dupe_9grams": 0.15672705, "qsc_code_frac_chars_dupe_10grams": 0.13026664, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.03079109, "qsc_code_frac_chars_whitespace": 0.12575925, "qsc_code_size_file_byte": 7244.0, "qsc_code_num_lines": 146.0, "qsc_code_num_chars_line_max": 241.0, "qsc_code_num_chars_line_mean": 49.61643836, "qsc_code_frac_chars_alphabet": 0.74498658, "qsc_code_frac_chars_comments": 0.0, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.19047619, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.15707384, "qsc_code_frac_chars_long_word_length": 0.01256039, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00441684, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codehtml_cate_ast": 1.0, "qsc_codehtml_frac_words_text": 0.47404749, "qsc_codehtml_num_chars_text": 3434.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_codehtml_cate_ast": 0, "qsc_codehtml_frac_words_text": 0, "qsc_codehtml_num_chars_text": 0} |
0-1-0/lightblue-0.4 | src/series60/_lightbluecommon.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
# Defines attributes with common implementations across the different
# platforms.
# public attributes
__all__ = ("L2CAP", "RFCOMM", "OBEX", "BluetoothError", "splitclass")
# Protocol/service class types, used for sockets and advertising services
L2CAP, RFCOMM, OBEX = (10, 11, 12)
class BluetoothError(IOError):
"""
Generic exception raised for Bluetooth errors. This is not raised for
socket-related errors; socket objects raise the socket.error and
socket.timeout exceptions from the standard library socket module.
Note that error codes are currently platform-independent. In particular,
the Mac OS X implementation returns IOReturn error values from the IOKit
framework, and OBEXError codes from <IOBluetooth/OBEX.h> for OBEX operations.
"""
pass
def splitclass(classofdevice):
"""
Splits the given class of device to return a 3-item tuple with the
major service class, major device class and minor device class values.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Example:
>>> splitclass(1057036)
(129, 1, 3)
>>>
"""
if not isinstance(classofdevice, int):
try:
classofdevice = int(classofdevice)
except (TypeError, ValueError):
raise TypeError("Given device class '%s' cannot be split" % \
str(classofdevice))
data = classofdevice >> 2 # skip over the 2 "format" bits
service = data >> 11
major = (data >> 6) & 0x1F
minor = data & 0x3F
return (service, major, minor)
_validbtaddr = None
def _isbtaddr(address):
"""
Returns whether the given address is a valid bluetooth address.
For example, "00:0e:6d:7b:a2:0a" is a valid address.
Returns False if the argument is None or is not a string.
"""
# Define validity regex. Accept either ":" or "-" as separators.
global _validbtaddr
if _validbtaddr is None:
import re
_validbtaddr = re.compile("((\d|[a-f]){2}(:|-)){5}(\d|[a-f]){2}",
re.IGNORECASE)
import types
if not isinstance(address, types.StringTypes):
return False
return _validbtaddr.match(address) is not None
# --------- other attributes ---------
def _joinclass(codtuple):
"""
The opposite of splitclass(). Joins a (service, major, minor) class-of-
device tuple into a whole class of device value.
"""
if not isinstance(codtuple, tuple):
raise TypeError("argument must be tuple, was %s" % type(codtuple))
if len(codtuple) != 3:
raise ValueError("tuple must have 3 items, has %d" % len(codtuple))
serviceclass = codtuple[0] << 2 << 11
majorclass = codtuple[1] << 2 << 6
minorclass = codtuple[2] << 2
return (serviceclass | majorclass | minorclass)
# Docstrings for socket objects.
# Based on std lib socket docs.
_socketdocs = {
"accept":
"""
accept() -> (socket object, address info)
Wait for an incoming connection. Return a new socket representing the
connection, and the address of the client. For RFCOMM sockets, the address
info is a pair (hostaddr, channel).
The socket must be bound and listening before calling this method.
""",
"bind":
"""
bind(address)
Bind the socket to a local address. For RFCOMM sockets, the address is a
pair (host, channel); the host must refer to the local host.
A port value of 0 binds the socket to a dynamically assigned port.
(Note that on Mac OS X, the port value must always be 0.)
The socket must not already be bound.
""",
"close":
"""
close()
Close the socket. It cannot be used after this call.
""",
"connect":
"""
connect(address)
Connect the socket to a remote address. The address should be a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
The socket must not be already connected.
""",
"connect_ex":
"""
connect_ex(address) -> errno
This is like connect(address), but returns an error code instead of raising
an exception when an error occurs.
""",
"dup":
"""
dup() -> socket object
Returns a new socket object connected to the same system resource.
""",
"fileno":
"""
fileno() -> integer
Return the integer file descriptor of the socket.
Raises NotImplementedError on Mac OS X and Python For Series 60.
""",
"getpeername":
"""
getpeername() -> address info
Return the address of the remote endpoint. The address info is a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
If the socket has not been connected, socket.error will be raised.
""",
"getsockname":
"""
getsockname() -> address info
Return the address of the local endpoint. The address info is a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
If the socket has not been connected nor bound, this returns the tuple
("00:00:00:00:00:00", 0).
""",
"getsockopt":
"""
getsockopt(level, option[, bufsize]) -> value
Get a socket option. See the Unix manual for level and option.
If a nonzero buffersize argument is given, the return value is a
string of that length; otherwise it is an integer.
Currently support for socket options are platform independent -- i.e.
depends on the underlying Series 60 or BlueZ socket options support.
The Mac OS X implementation currently does not support any options at
all and automatically raises socket.error.
""",
"gettimeout":
"""
gettimeout() -> timeout
Returns the timeout in floating seconds associated with socket
operations. A timeout of None indicates that timeouts on socket
operations are disabled.
Currently not supported on Python For Series 60 implementation, which
will always return None.
""",
"listen":
"""
listen(backlog)
Enable a server to accept connections. The backlog argument must be at
least 1; it specifies the number of unaccepted connection that the system
will allow before refusing new connections.
The socket must not be already listening.
Currently not implemented on Mac OS X.
""",
"makefile":
"""
makefile([mode[, bufsize]]) -> file object
Returns a regular file object corresponding to the socket. The mode
and bufsize arguments are as for the built-in open() function.
""",
"recv":
"""
recv(bufsize[, flags]) -> data
Receive up to bufsize bytes from the socket. For the optional flags
argument, see the Unix manual. When no data is available, block until
at least one byte is available or until the remote end is closed. When
the remote end is closed and all data is read, return the empty string.
Currently the flags argument has no effect on Mac OS X.
""",
"recvfrom":
"""
recvfrom(bufsize[, flags]) -> (data, address info)
Like recv(buffersize, flags) but also return the sender's address info.
""",
"send":
"""
send(data[, flags]) -> count
Send a data string to the socket. For the optional flags
argument, see the Unix manual. Return the number of bytes
sent.
The socket must be connected to a remote socket.
Currently the flags argument has no effect on Mac OS X.
""",
"sendall":
"""
sendall(data[, flags])
Send a data string to the socket. For the optional flags
argument, see the Unix manual. This calls send() repeatedly
until all data is sent. If an error occurs, it's impossible
to tell how much data has been sent.
""",
"sendto":
"""
sendto(data[, flags], address) -> count
Like send(data, flags) but allows specifying the destination address.
For RFCOMM sockets, the address is a pair (hostaddr, channel).
""",
"setblocking":
"""
setblocking(flag)
Set the socket to blocking (flag is true) or non-blocking (false).
setblocking(True) is equivalent to settimeout(None);
setblocking(False) is equivalent to settimeout(0.0).
Initially a socket is in blocking mode. In non-blocking mode, if a
socket operation cannot be performed immediately, socket.error is raised.
The underlying implementation on Python for Series 60 only supports
non-blocking mode for send() and recv(), and ignores it for connect() and
accept().
""",
"setsockopt":
"""
setsockopt(level, option, value)
Set a socket option. See the Unix manual for level and option.
The value argument can either be an integer or a string.
Currently support for socket options are platform independent -- i.e.
depends on the underlying Series 60 or BlueZ socket options support.
The Mac OS X implementation currently does not support any options at
all and automatically raise socket.error.
""",
"settimeout":
"""
settimeout(timeout)
Set a timeout on socket operations. 'timeout' can be a float,
giving in seconds, or None. Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
If a timeout is set, the connect, accept, send and receive operations will
raise socket.timeout if a timeout occurs.
Raises NotImplementedError on Python For Series 60.
""",
"shutdown":
"""
shutdown(how)
Shut down the reading side of the socket (flag == socket.SHUT_RD), the
writing side of the socket (flag == socket.SHUT_WR), or both ends
(flag == socket.SHUT_RDWR).
"""
}
| 10,831 | _lightbluecommon | py | en | python | code | {"qsc_code_num_words": 1463, "qsc_code_num_chars": 10831.0, "qsc_code_mean_word_length": 4.88311688, "qsc_code_frac_words_unique": 0.2836637, "qsc_code_frac_chars_top_2grams": 0.02519597, "qsc_code_frac_chars_top_3grams": 0.00671892, "qsc_code_frac_chars_top_4grams": 0.0055991, "qsc_code_frac_chars_dupe_5grams": 0.22074468, "qsc_code_frac_chars_dupe_6grams": 0.18924972, "qsc_code_frac_chars_dupe_7grams": 0.17441209, "qsc_code_frac_chars_dupe_8grams": 0.15733483, "qsc_code_frac_chars_dupe_9grams": 0.15733483, "qsc_code_frac_chars_dupe_10grams": 0.14613662, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01130716, "qsc_code_frac_chars_whitespace": 0.25694765, "qsc_code_size_file_byte": 10831.0, "qsc_code_num_lines": 331.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 32.72205438, "qsc_code_frac_chars_alphabet": 0.8763668, "qsc_code_frac_chars_comments": 0.20801403, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.1814301, "qsc_code_frac_chars_long_word_length": 0.01921025, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00426894, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.03703704, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.01234568, "qsc_codepython_frac_lines_import": 0.02469136, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.12345679, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/LloydsBeacon.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.LockedFloor;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfTeleportation;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.plants.Swiftthistle;
import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.InterlevelScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSprite.Glowing;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.PathFinder;
import java.util.ArrayList;
public class LloydsBeacon extends Artifact {
public static final float TIME_TO_USE = 1;
public static final String AC_ZAP = "ZAP";
public static final String AC_SET = "SET";
public static final String AC_RETURN = "RETURN";
public int returnDepth = -1;
public int returnPos;
{
image = ItemSpriteSheet.ARTIFACT_BEACON;
levelCap = 3;
charge = 0;
chargeCap = 3+level();
defaultAction = AC_ZAP;
usesTargeting = true;
}
private static final String DEPTH = "depth";
private static final String POS = "pos";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( DEPTH, returnDepth );
if (returnDepth != -1) {
bundle.put( POS, returnPos );
}
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle(bundle);
returnDepth = bundle.getInt( DEPTH );
returnPos = bundle.getInt( POS );
}
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
actions.add( AC_ZAP );
actions.add( AC_SET );
if (returnDepth != -1) {
actions.add( AC_RETURN );
}
return actions;
}
@Override
public void execute( Hero hero, String action ) {
super.execute( hero, action );
if (action == AC_SET || action == AC_RETURN) {
if (Dungeon.bossLevel()) {
hero.spend( LloydsBeacon.TIME_TO_USE );
GLog.w( Messages.get(this, "preventing") );
return;
}
for (int i = 0; i < PathFinder.NEIGHBOURS8.length; i++) {
Char ch = Actor.findChar(hero.pos + PathFinder.NEIGHBOURS8[i]);
if (ch != null && ch.alignment == Char.Alignment.ENEMY) {
GLog.w( Messages.get(this, "creatures") );
return;
}
}
}
if (action == AC_ZAP ){
curUser = hero;
int chargesToUse = Dungeon.depth > 20 ? 2 : 1;
if (!isEquipped( hero )) {
GLog.i( Messages.get(Artifact.class, "need_to_equip") );
QuickSlotButton.cancel();
} else if (charge < chargesToUse) {
GLog.i( Messages.get(this, "no_charge") );
QuickSlotButton.cancel();
} else {
GameScene.selectCell(zapper);
}
} else if (action == AC_SET) {
returnDepth = Dungeon.depth;
returnPos = hero.pos;
hero.spend( LloydsBeacon.TIME_TO_USE );
hero.busy();
hero.sprite.operate( hero.pos );
Sample.INSTANCE.play( Assets.SND_BEACON );
GLog.i( Messages.get(this, "return") );
} else if (action == AC_RETURN) {
if (returnDepth == Dungeon.depth) {
ScrollOfTeleportation.appear( hero, returnPos );
for(Mob m : Dungeon.level.mobs){
if (m.pos == hero.pos){
//displace mob
for(int i : PathFinder.NEIGHBOURS8){
if (Actor.findChar(m.pos+i) == null && Dungeon.level.passable[m.pos + i]){
m.pos += i;
m.sprite.point(m.sprite.worldToCamera(m.pos));
break;
}
}
}
}
Dungeon.level.occupyCell(hero );
Dungeon.observe();
GameScene.updateFog();
} else {
Buff buff = Dungeon.hero.buff(TimekeepersHourglass.timeFreeze.class);
if (buff != null) buff.detach();
buff = Dungeon.hero.buff(Swiftthistle.TimeBubble.class);
if (buff != null) buff.detach();
InterlevelScene.mode = InterlevelScene.Mode.RETURN;
InterlevelScene.returnDepth = returnDepth;
InterlevelScene.returnPos = returnPos;
Game.switchScene( InterlevelScene.class );
}
}
}
protected CellSelector.Listener zapper = new CellSelector.Listener() {
@Override
public void onSelect(Integer target) {
if (target == null) return;
Invisibility.dispel();
charge -= Dungeon.depth > 20 ? 2 : 1;
updateQuickslot();
if (Actor.findChar(target) == curUser){
ScrollOfTeleportation.teleportHero(curUser);
curUser.spendAndNext(1f);
} else {
final Ballistica bolt = new Ballistica( curUser.pos, target, Ballistica.MAGIC_BOLT );
final Char ch = Actor.findChar(bolt.collisionPos);
if (ch == curUser){
ScrollOfTeleportation.teleportHero(curUser);
curUser.spendAndNext( 1f );
} else {
Sample.INSTANCE.play( Assets.SND_ZAP );
curUser.sprite.zap(bolt.collisionPos);
curUser.busy();
MagicMissile.boltFromChar(curUser.sprite.parent,
MagicMissile.BEACON,
curUser.sprite,
bolt.collisionPos,
new Callback() {
@Override
public void call() {
if (ch != null) {
int count = 10;
int pos;
do {
pos = Dungeon.level.randomRespawnCell();
if (count-- <= 0) {
break;
}
} while (pos == -1);
if (pos == -1 || Dungeon.bossLevel()) {
GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") );
} else if (ch.properties().contains(Char.Property.IMMOVABLE)) {
GLog.w( Messages.get(LloydsBeacon.class, "tele_fail") );
} else {
ch.pos = pos;
if (ch instanceof Mob && ((Mob) ch).state == ((Mob) ch).HUNTING){
((Mob) ch).state = ((Mob) ch).WANDERING;
}
ch.sprite.place(ch.pos);
ch.sprite.visible = Dungeon.level.heroFOV[pos];
}
}
curUser.spendAndNext(1f);
}
});
}
}
}
@Override
public String prompt() {
return Messages.get(LloydsBeacon.class, "prompt");
}
};
@Override
protected ArtifactBuff passiveBuff() {
return new beaconRecharge();
}
@Override
public void charge(Hero target) {
if (charge < chargeCap){
partialCharge += 0.25f;
if (partialCharge >= 1){
partialCharge--;
charge++;
updateQuickslot();
}
}
}
@Override
public Item upgrade() {
if (level() == levelCap) return this;
chargeCap ++;
GLog.p( Messages.get(this, "levelup") );
return super.upgrade();
}
@Override
public String desc() {
String desc = super.desc();
if (returnDepth != -1){
desc += "\n\n" + Messages.get(this, "desc_set", returnDepth);
}
return desc;
}
private static final Glowing WHITE = new Glowing( 0xFFFFFF );
@Override
public Glowing glowing() {
return returnDepth != -1 ? WHITE : null;
}
public class beaconRecharge extends ArtifactBuff{
@Override
public boolean act() {
LockedFloor lock = target.buff(LockedFloor.class);
if (charge < chargeCap && !cursed && (lock == null || lock.regenOn())) {
partialCharge += 1 / (100f - (chargeCap - charge)*10f);
if (partialCharge >= 1) {
partialCharge --;
charge ++;
if (charge == chargeCap){
partialCharge = 0;
}
}
}
updateQuickslot();
spend( TICK );
return true;
}
}
}
| 9,160 | LloydsBeacon | java | en | java | code | {"qsc_code_num_words": 1000, "qsc_code_num_chars": 9160.0, "qsc_code_mean_word_length": 6.148, "qsc_code_frac_words_unique": 0.276, "qsc_code_frac_chars_top_2grams": 0.03952505, "qsc_code_frac_chars_top_3grams": 0.14216005, "qsc_code_frac_chars_top_4grams": 0.15744958, "qsc_code_frac_chars_dupe_5grams": 0.23649967, "qsc_code_frac_chars_dupe_6grams": 0.0772609, "qsc_code_frac_chars_dupe_7grams": 0.02342225, "qsc_code_frac_chars_dupe_8grams": 0.02342225, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00811108, "qsc_code_frac_chars_whitespace": 0.2058952, "qsc_code_size_file_byte": 9160.0, "qsc_code_num_lines": 337.0, "qsc_code_num_chars_line_max": 90.0, "qsc_code_num_chars_line_mean": 27.1810089, "qsc_code_frac_chars_alphabet": 0.83709101, "qsc_code_frac_chars_comments": 0.08679039, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.17928287, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01291094, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00095637, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05179283, "qsc_codejava_score_lines_no_logic": 0.19920319, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 0.5, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/CapeOfThorns.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.utils.Random;
public class CapeOfThorns extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_CAPE;
levelCap = 10;
charge = 0;
chargeCap = 100;
cooldown = 0;
defaultAction = "NONE"; //so it can be quickslotted
}
@Override
protected ArtifactBuff passiveBuff() {
return new Thorns();
}
@Override
public void charge(Hero target) {
if (cooldown == 0) {
charge += 4;
updateQuickslot();
}
if (charge >= chargeCap){
target.buff(Thorns.class).proc(0, null, null);
}
}
@Override
public String desc() {
String desc = Messages.get(this, "desc");
if (isEquipped( Dungeon.hero )) {
desc += "\n\n";
if (cooldown == 0)
desc += Messages.get(this, "desc_inactive");
else
desc += Messages.get(this, "desc_active");
}
return desc;
}
public class Thorns extends ArtifactBuff{
@Override
public boolean act(){
if (cooldown > 0) {
cooldown--;
if (cooldown == 0) {
BuffIndicator.refreshHero();
GLog.w( Messages.get(this, "inert") );
}
updateQuickslot();
}
spend(TICK);
return true;
}
public int proc(int damage, Char attacker, Char defender){
if (cooldown == 0){
charge += damage*(0.5+level()*0.05);
if (charge >= chargeCap){
charge = 0;
cooldown = 10+level();
GLog.p( Messages.get(this, "radiating") );
BuffIndicator.refreshHero();
}
}
if (cooldown != 0){
int deflected = Random.NormalIntRange(0, damage);
damage -= deflected;
if (attacker != null && Dungeon.level.adjacent(attacker.pos, defender.pos)) {
attacker.damage(deflected, this);
}
exp+= deflected;
if (exp >= (level()+1)*5 && level() < levelCap){
exp -= (level()+1)*5;
upgrade();
GLog.p( Messages.get(this, "levelup") );
}
}
updateQuickslot();
return damage;
}
@Override
public String toString() {
return Messages.get(this, "name");
}
@Override
public String desc() {
return Messages.get(this, "desc", dispTurns(cooldown));
}
@Override
public int icon() {
if (cooldown == 0)
return BuffIndicator.NONE;
else
return BuffIndicator.THORNS;
}
@Override
public void detach(){
cooldown = 0;
charge = 0;
super.detach();
}
}
}
| 3,568 | CapeOfThorns | java | en | java | code | {"qsc_code_num_words": 419, "qsc_code_num_chars": 3568.0, "qsc_code_mean_word_length": 5.73508353, "qsc_code_frac_words_unique": 0.39856802, "qsc_code_frac_chars_top_2grams": 0.03370787, "qsc_code_frac_chars_top_3grams": 0.12650853, "qsc_code_frac_chars_top_4grams": 0.12817312, "qsc_code_frac_chars_dupe_5grams": 0.12109863, "qsc_code_frac_chars_dupe_6grams": 0.0233042, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01690736, "qsc_code_frac_chars_whitespace": 0.20431614, "qsc_code_size_file_byte": 3568.0, "qsc_code_num_lines": 152.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 23.47368421, "qsc_code_frac_chars_alphabet": 0.82951744, "qsc_code_frac_chars_comments": 0.2264574, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.27102804, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.02355072, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08411215, "qsc_codejava_score_lines_no_logic": 0.20560748, "qsc_codejava_frac_words_no_modifier": 0.81818182, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/series60/obex.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"""
Provides an OBEX client class and convenience functions for sending and
receiving files over OBEX.
This module also defines constants for response code values (without the final
bit set). For example:
>>> import lightblue
>>> lightblue.obex.OK
32 # the OK/Success response 0x20 (i.e. 0xA0 without the final bit)
>>> lightblue.obex.FORBIDDEN
67 # the Forbidden response 0x43 (i.e. 0xC3 without the final bit)
"""
# Docstrings for attributes in this module.
_docstrings = {
"sendfile":
"""
Sends a file to a remote device.
Raises lightblue.obex.OBEXError if an error occurred during the request, or
if the request was refused by the remote device.
Arguments:
- address: the address of the remote device
- channel: the RFCOMM channel of the remote OBEX service
- source: a filename or file-like object, containing the data to be
sent. If a file object is given, it must be opened for reading.
Note you can achieve the same thing using OBEXClient with something like
this:
>>> import lightblue
>>> client = lightblue.obex.OBEXClient(address, channel)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> putresponse = client.put({"name": "MyFile.txt"}, file("MyFile.txt", 'rb'))
>>> client.disconnect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> if putresponse.code != lightblue.obex.OK:
... raise lightblue.obex.OBEXError("server denied the Put request")
>>>
""",
"recvfile":
"""
Receives a file through an OBEX service.
Arguments:
- sock: the server socket on which the file is to be received. Note
this socket must *not* be listening. Also, an OBEX service should
have been advertised on this socket.
- dest: a filename or file-like object, to which the received data will
be written. If a filename is given, any existing file will be
overwritten. If a file object is given, it must be opened for writing.
For example, to receive a file and save it as "MyFile.txt":
>>> from lightblue import *
>>> s = socket()
>>> s.bind(("", 0))
>>> advertise("My OBEX Service", s, OBEX)
>>> obex.recvfile(s, "MyFile.txt")
"""
}
# import implementation modules
from _obex import *
from _obexcommon import *
import _obex
import _obexcommon
__all__ = _obex.__all__ + _obexcommon.__all__
# set docstrings
localattrs = locals()
for attr in _obex.__all__:
try:
localattrs[attr].__doc__ = _docstrings[attr]
except KeyError:
pass
del attr, localattrs
| 3,421 | obex | py | en | python | code | {"qsc_code_num_words": 468, "qsc_code_num_chars": 3421.0, "qsc_code_mean_word_length": 4.86752137, "qsc_code_frac_words_unique": 0.41880342, "qsc_code_frac_chars_top_2grams": 0.03424056, "qsc_code_frac_chars_top_3grams": 0.01712028, "qsc_code_frac_chars_top_4grams": 0.02502195, "qsc_code_frac_chars_dupe_5grams": 0.12467076, "qsc_code_frac_chars_dupe_6grams": 0.11325724, "qsc_code_frac_chars_dupe_7grams": 0.0667252, "qsc_code_frac_chars_dupe_8grams": 0.03248464, "qsc_code_frac_chars_dupe_9grams": 0.03248464, "qsc_code_frac_chars_dupe_10grams": 0.03248464, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01152074, "qsc_code_frac_chars_whitespace": 0.23881906, "qsc_code_size_file_byte": 3421.0, "qsc_code_num_lines": 97.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 35.26804124, "qsc_code_frac_chars_alphabet": 0.86328725, "qsc_code_frac_chars_comments": 0.35311312, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.04324324, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.05882353, "qsc_codepython_frac_lines_import": 0.23529412, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.23529412, "qsc_codepython_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 1, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/series60/_obexcommon.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
import _lightbluecommon
__all__ = ('OBEXResponse', 'OBEXError',
'CONTINUE', 'OK', 'CREATED', 'ACCEPTED', 'NON_AUTHORITATIVE_INFORMATION',
'NO_CONTENT', 'RESET_CONTENT', 'PARTIAL_CONTENT',
'MULTIPLE_CHOICES', 'MOVED_PERMANENTLY', 'MOVED_TEMPORARILY', 'SEE_OTHER',
'NOT_MODIFIED', 'USE_PROXY',
'BAD_REQUEST', 'UNAUTHORIZED', 'PAYMENT_REQUIRED', 'FORBIDDEN',
'NOT_FOUND', 'METHOD_NOT_ALLOWED', 'NOT_ACCEPTABLE',
'PROXY_AUTHENTICATION_REQUIRED', 'REQUEST_TIME_OUT', 'CONFLICT', 'GONE',
'LENGTH_REQUIRED', 'PRECONDITION_FAILED', 'REQUESTED_ENTITY_TOO_LARGE',
'REQUEST_URL_TOO_LARGE', 'UNSUPPORTED_MEDIA_TYPE',
'INTERNAL_SERVER_ERROR', 'NOT_IMPLEMENTED', 'BAD_GATEWAY',
'SERVICE_UNAVAILABLE', 'GATEWAY_TIMEOUT', 'HTTP_VERSION_NOT_SUPPORTED',
'DATABASE_FULL', 'DATABASE_LOCKED')
class OBEXError(_lightbluecommon.BluetoothError):
"""
Generic exception raised for OBEX-related errors.
"""
pass
class OBEXResponse:
"""
Contains the OBEX response received from an OBEX server.
When an OBEX client sends a request, the OBEX server sends back a response
code (to indicate whether the request was successful) and a set of response
headers (to provide other useful information).
For example, if a client sends a 'Get' request to retrieve a file, the
client might get a response like this:
>>> import lightblue
>>> client = lightblue.obex.OBEXClient("aa:bb:cc:dd:ee:ff", 10)
>>> response = client.get({"name": "file.txt"}, file("file.txt", "w"))
>>> print response
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={'length': 35288}>
You can get the response code and response headers in different formats:
>>> print response.reason
'OK' # a string description of the response code
>>> print response.code
32 # the response code (e.g. this is 0x20)
>>> print response.headers
{'length': 35288} # the headers, with string keys
>>> print response.rawheaders
{195: 35288} # the headers, with raw header ID keys
>>>
Note how the 'code' attribute does not have the final bit set - e.g. for
OK/Success, the response code is 0x20, not 0xA0.
The lightblue.obex module defines constants for response code values (e.g.
lightblue.obex.OK, lightblue.obex.FORBIDDEN, etc.).
"""
def __init__(self, code, rawheaders):
self.__code = code
self.__reason = _OBEX_RESPONSES.get(code, "Unknown response code")
self.__rawheaders = rawheaders
self.__headers = None
code = property(lambda self: self.__code,
doc='The response code, without the final bit set.')
reason = property(lambda self: self.__reason,
doc='A string description of the response code.')
rawheaders = property(lambda self: self.__rawheaders,
doc='The response headers, as a dictionary with header ID (unsigned byte) keys.')
def getheader(self, header, default=None):
'''
Returns the response header value for the given header, which may
either be a string (not case-sensitive) or the raw byte
value of the header ID.
Returns the specified default value if the header is not present.
'''
if isinstance(header, types.StringTypes):
return self.headers.get(header.lower(), default)
return self.__rawheaders.get(header, default)
def __getheaders(self):
if self.__headers is None:
self.__headers = {}
for headerid, value in self.__rawheaders.items():
if headerid in _HEADER_IDS_TO_STRINGS:
self.__headers[_HEADER_IDS_TO_STRINGS[headerid]] = value
else:
self.__headers["0x%02x" % headerid] = value
return self.__headers
headers = property(__getheaders,
doc='The response headers, as a dictionary with string keys.')
def __repr__(self):
return "<OBEXResponse reason='%s' code=0x%02x (0x%02x) headers=%s>" % \
(self.__reason, self.__code, (self.__code | 0x80), str(self.headers))
try:
import datetime
# as from python docs example
class UTC(datetime.tzinfo):
"""UTC"""
def utcoffset(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return datetime.timedelta(0)
except:
pass # no datetime on pys60
_LOCAL_TIME_FORMAT = "%Y%m%dT%H%M%S"
_UTC_TIME_FORMAT = _LOCAL_TIME_FORMAT + "Z"
def _datetimefromstring(s):
import time
if s[-1:] == "Z":
# add UTC() instance as tzinfo
args = (time.strptime(s, _UTC_TIME_FORMAT)[0:6]) + (0, UTC())
return datetime.datetime(*args)
else:
return datetime.datetime(*(time.strptime(s, _LOCAL_TIME_FORMAT)[0:6]))
_HEADER_STRINGS_TO_IDS = {
"count": 0xc0,
"name": 0x01,
"type": 0x42,
"length": 0xc3,
"time": 0x44,
"description": 0x05,
"target": 0x46,
"http": 0x47,
"who": 0x4a,
"connection-id": 0xcb,
"application-parameters": 0x4c,
"authentication-challenge": 0x4d,
"authentication-response": 0x4e,
"creator-id": 0xcf,
"wan-uuid": 0x50,
"object-class": 0x51,
"session-parameters": 0x52,
"session-sequence-number": 0x93
}
_HEADER_IDS_TO_STRINGS = {}
for key, value in _HEADER_STRINGS_TO_IDS.items():
_HEADER_IDS_TO_STRINGS[value] = key
assert len(_HEADER_IDS_TO_STRINGS) == len(_HEADER_STRINGS_TO_IDS)
# These match the associated strings in httplib.responses, since OBEX response
# codes are matched to HTTP status codes (except for 0x60 and 0x61).
# Note these are the responses *without* the final bit set.
_OBEX_RESPONSES = {
0x10: "Continue",
0x20: "OK",
0x21: "Created",
0x22: "Accepted",
0x23: "Non-Authoritative Information",
0x24: "No Content",
0x25: "Reset Content",
0x26: "Partial Content",
0x30: "Multiple Choices",
0x31: "Moved Permanently",
0x32: "Moved Temporarily", # but is 'Found' (302) in httplib.response???
0x33: "See Other",
0x34: "Not Modified",
0x35: "Use Proxy",
0x40: "Bad Request",
0x41: "Unauthorized",
0x42: "Payment Required",
0x43: "Forbidden",
0x44: "Not Found",
0x45: "Method Not Allowed",
0x46: "Not Acceptable",
0x47: "Proxy Authentication Required",
0x48: "Request Timeout",
0x49: "Conflict",
0x4A: "Gone",
0x48: "Length Required",
0x4C: "Precondition Failed",
0x4D: "Request Entity Too Large",
0x4E: "Request-URI Too Long",
0x4F: "Unsupported Media Type",
0x50: "Internal Server Error",
0x51: "Not Implemented",
0x52: "Bad Gateway",
0x53: "Service Unavailable",
0x54: "Gateway Timeout",
0x55: "HTTP Version Not Supported",
0x60: "Database Full",
0x61: "Database Locked"
}
_obexclientclassdoc = \
"""
An OBEX client class. (Note this is not available on Python for Series 60.)
For example, to connect to an OBEX server and send a file:
>>> import lightblue
>>> client = lightblue.obex.OBEXClient("aa:bb:cc:dd:ee:ff", 10)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> client.put({"name": "photo.jpg"}, file("photo.jpg", "rb"))
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> client.disconnect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>>
A client must call connect() to establish a connection before it can send
any other requests.
The connect(), disconnect(), put(), delete(), get() and setpath() methods
all accept the request headers as a dictionary of header-value mappings. The
request headers are used to provide the server with additional information
for the request. For example, this sends a Put request that includes Name,
Type and Length headers in the request headers, to provide details about
the transferred file:
>>> f = file("file.txt")
>>> client.put({"name": "file.txt", "type": "text/plain",
... "length": 5192}, f)
>>>
Here is a list of all the different string header keys that you can use in
the request headers, and the expected type of the value for each header:
- "name" -> a string
- "type" -> a string
- "length" -> an int
- "time" -> a datetime object from the datetime module
- "description" -> a string
- "target" -> a string or buffer
- "http" -> a string or buffer
- "who" -> a string or buffer
- "connection-id" -> an int
- "application-parameters" -> a string or buffer
- "authentication-challenge" -> a string or buffer
- "authentication-response" -> a string or buffer
- "creator-id" -> an int
- "wan-uuid" -> a string or buffer
- "object-class" -> a string or buffer
- "session-parameters" -> a string or buffer
- "session-sequence-number" -> an int less than 256
(The string header keys are not case-sensitive.)
Alternatively, you can use raw header ID values instead of the above
convenience strings. So, the previous example can be rewritten as:
>>> client.put({0x01: "file.txt", 0x42: "text/plain", 0xC3: 5192},
... fileobject)
>>>
This is also useful for inserting custom headers. For example, a PutImage
request for a Basic Imaging client requires the Img-Descriptor (0x71)
header:
>>> client.put({"type": "x-bt/img-img",
... "name": "photo.jpg",
... 0x71: '<image-descriptor version="1.0"><image encoding="JPEG" pixel="160*120" size="37600"/></image-descriptor>'},
... file('photo.jpg', 'rb'))
>>>
Notice that the connection-id header is not sent, because this is
automatically included by OBEXClient in the request headers if a
connection-id was received in a previous Connect response.
See the included src/examples/obex_ftp_client.py for an example of using
OBEXClient to implement a File Transfer client for browsing the files on a
remote device.
"""
_obexclientdocs = {
"__init__":
"""
Creates an OBEX client.
Arguments:
- address: the address of the remote device
- channel: the RFCOMM channel of the remote OBEX service
""",
"connect":
"""
Establishes the Bluetooth connection to the remote OBEX server and sends
a Connect request to open the OBEX session. Returns an OBEXResponse
instance containing the server response.
Raises lightblue.obex.OBEXError if the session is already connected, or if
an error occurs during the request.
If the server refuses the Connect request (i.e. if it sends a response code
other than OK/Success), the Bluetooth connection will be closed.
Arguments:
- headers={}: the headers to send for the Connect request
""",
"disconnect":
"""
Sends a Disconnect request to end the OBEX session and closes the Bluetooth
connection to the remote OBEX server. Returns an OBEXResponse
instance containing the server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers={}: the headers to send for the request
""",
"put":
"""
Sends a Put request. Returns an OBEXResponse instance containing the
server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request
- fileobj: a file-like object containing the file data to be sent for
the request
For example, to send a file named 'photo.jpg', using the request headers
to notify the server of the file's name, MIME type and length:
>>> client = lightblue.obex.OBEXClient("aa:bb:cc:dd:ee:ff", 10)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> client.put({"name": "photo.jpg", "type": "image/jpeg",
"length": 28566}, file("photo.jpg", "rb"))
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>>
""",
"delete":
"""
Sends a Put-Delete request in order to delete a file or folder on the remote
server. Returns an OBEXResponse instance containing the server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request - you should use the
'name' header to specify the file you want to delete
If the file on the server can't be deleted because it's a read-only file,
you might get an 'Unauthorized' response, like this:
>>> client = lightblue.obex.OBEXClient("aa:bb:cc:dd:ee:ff", 10)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> client.delete({"name": "random_file.txt"})
<OBEXResponse reason='Unauthorized' code=0x41 (0xc1) headers={}>
>>>
""",
"get":
"""
Sends a Get request. Returns an OBEXResponse instance containing the server
response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request - you should use these
to specify the file you want to retrieve
- fileobj: a file-like object, to which the received data will be
written
An example:
>>> client = lightblue.obex.OBEXClient("aa:bb:cc:dd:ee:ff", 10)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> f = file("received_file.txt", "w+")
>>> client.get({"name": "testfile.txt"}, f)
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={'length':9}>
>>> f.seek(0)
>>> f.read()
'test file'
>>>
""",
"setpath":
"""
Sends a SetPath request in order to set the "current path" on the remote
server for file transfers. Returns an OBEXResponse instance containing the
server response.
Raises lightblue.obex.OBEXError if connect() has not been called, or if an
error occurs during the request.
Note that you don't need to send any connection-id headers - this is
automatically included if the client received one in a Connect response.
Arguments:
- headers: the headers to send for the request - you should use the
'name' header to specify the directory you want to change to
- cdtoparent=False: True if the remote server should move up one
directory before applying the specified directory (i.e. 'cd
../dirname')
- createdirs=False: True if the specified directory should be created
if it doesn't exist (if False, the server will return an error
response if the directory doesn't exist)
For example:
# change to the "images" subdirectory
>>> client.setpath({"name": "images"})
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>>
# change to the parent directory
>>> client.setpath({}, cdtoparent=True)
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>>
# create a subdirectory "My_Files"
>>> client.setpath({"name": "My_Files"}, createdirs=True)
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>>
# change to the root directory - you can use an empty "name" header
# to specify this
>>> client.setpath({"name": ""})
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>>
"""
}
# response constants
CONTINUE = 0x10
OK = 0x20
CREATED = 0x21
ACCEPTED = 0x22
NON_AUTHORITATIVE_INFORMATION = 0x23
NO_CONTENT = 0x24
RESET_CONTENT = 0x25
PARTIAL_CONTENT = 0x26
MULTIPLE_CHOICES = 0x30
MOVED_PERMANENTLY = 0x31
MOVED_TEMPORARILY = 0x32
SEE_OTHER = 0x33
NOT_MODIFIED = 0x34
USE_PROXY = 0x35
BAD_REQUEST = 0x40
UNAUTHORIZED = 0x41
PAYMENT_REQUIRED = 0x42
FORBIDDEN = 0x43
NOT_FOUND = 0x44
METHOD_NOT_ALLOWED = 0x45
NOT_ACCEPTABLE = 0x46
PROXY_AUTHENTICATION_REQUIRED = 0x47
REQUEST_TIME_OUT = 0x48
CONFLICT = 0x49
GONE = 0x4A
LENGTH_REQUIRED = 0x4B
PRECONDITION_FAILED = 0x4C
REQUESTED_ENTITY_TOO_LARGE = 0x4D
REQUEST_URL_TOO_LARGE = 0x4E
UNSUPPORTED_MEDIA_TYPE = 0x4F
INTERNAL_SERVER_ERROR = 0x50
NOT_IMPLEMENTED = 0x51
BAD_GATEWAY = 0x52
SERVICE_UNAVAILABLE = 0x53
GATEWAY_TIMEOUT = 0x54
HTTP_VERSION_NOT_SUPPORTED = 0x55
DATABASE_FULL = 0x60
DATABASE_LOCKED = 0x61
| 18,262 | _obexcommon | py | en | python | code | {"qsc_code_num_words": 2361, "qsc_code_num_chars": 18262.0, "qsc_code_mean_word_length": 4.96103346, "qsc_code_frac_words_unique": 0.21304532, "qsc_code_frac_chars_top_2grams": 0.01707504, "qsc_code_frac_chars_top_3grams": 0.02219756, "qsc_code_frac_chars_top_4grams": 0.02663707, "qsc_code_frac_chars_dupe_5grams": 0.2870315, "qsc_code_frac_chars_dupe_6grams": 0.26312644, "qsc_code_frac_chars_dupe_7grams": 0.25322291, "qsc_code_frac_chars_dupe_8grams": 0.23734312, "qsc_code_frac_chars_dupe_9grams": 0.20575429, "qsc_code_frac_chars_dupe_10grams": 0.20575429, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.03280592, "qsc_code_frac_chars_whitespace": 0.24553718, "qsc_code_size_file_byte": 18262.0, "qsc_code_num_lines": 515.0, "qsc_code_num_chars_line_max": 132.0, "qsc_code_num_chars_line_mean": 35.46019417, "qsc_code_frac_chars_alphabet": 0.81731746, "qsc_code_frac_chars_comments": 0.14286497, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0326087, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.28484848, "qsc_code_frac_chars_long_word_length": 0.04478114, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.06397306, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.00543478, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.04347826, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.01086957, "qsc_codepython_frac_lines_import": 0.01630435, "qsc_codepython_frac_lines_simplefunc": 0.021739130434782608, "qsc_codepython_score_lines_no_logic": 0.14673913, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/AlchemistsToolkit.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.items.Recipe;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.AlchemyScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.watabou.noosa.Game;
import com.watabou.utils.Bundle;
import com.watabou.utils.GameMath;
import java.util.ArrayList;
public class AlchemistsToolkit extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_TOOLKIT;
defaultAction = AC_BREW;
levelCap = 10;
charge = 0;
partialCharge = 0;
chargeCap = 100;
}
public static final String AC_BREW = "BREW";
protected WndBag.Mode mode = WndBag.Mode.POTION;
private boolean alchemyReady = false;
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (isEquipped( hero ) && !cursed)
actions.add(AC_BREW);
return actions;
}
@Override
public void execute(Hero hero, String action ) {
super.execute(hero, action);
if (action.equals(AC_BREW)){
if (!isEquipped(hero)) GLog.i( Messages.get(this, "need_to_equip") );
else if (cursed) GLog.w( Messages.get(this, "cursed") );
else if (!alchemyReady) GLog.i( Messages.get(this, "not_ready") );
else if (hero.visibleEnemies() > hero.mindVisionEnemies.size()) GLog.i( Messages.get(this, "enemy_near") );
else {
AlchemyScene.setProvider(hero.buff(kitEnergy.class));
Game.switchScene(AlchemyScene.class);
}
}
}
@Override
protected ArtifactBuff passiveBuff() {
return new kitEnergy();
}
@Override
public void charge(Hero target) {
if (charge < chargeCap){
partialCharge += 0.5f;
if (partialCharge >= 1){
partialCharge--;
charge++;
updateQuickslot();
}
}
}
public void absorbEnergy( int energy ){
exp += energy;
while (exp >= 10 && level() < levelCap){
upgrade();
exp -= 10;
}
if (level() == levelCap){
partialCharge += exp;
energy -= exp;
exp = 0;
}
partialCharge += energy/3f;
while (partialCharge >= 1){
partialCharge -= 1;
charge++;
if (charge >= chargeCap){
charge = chargeCap;
partialCharge = 0;
break;
}
}
updateQuickslot();
}
@Override
public String desc() {
String result = Messages.get(this, "desc");
if (isEquipped(Dungeon.hero)) {
if (cursed) result += "\n\n" + Messages.get(this, "desc_cursed");
else if (!alchemyReady) result += "\n\n" + Messages.get(this, "desc_warming");
else result += "\n\n" + Messages.get(this, "desc_hint");
}
return result;
}
@Override
public boolean doEquip(Hero hero) {
if (super.doEquip(hero)){
alchemyReady = false;
return true;
} else {
return false;
}
}
private static final String READY = "ready";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put(READY, alchemyReady);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
alchemyReady = bundle.getBoolean(READY);
}
public class kitEnergy extends ArtifactBuff implements AlchemyScene.AlchemyProvider {
public void gainCharge(float levelPortion) {
alchemyReady = true;
if (cursed) return;
if (charge < chargeCap) {
//generates 2 energy every hero level, +0.1 energy per toolkit level
//to a max of 12 energy per hero level
//This means that energy absorbed into the kit is recovered in 6.67 hero levels (as 33% of input energy is kept)
//exp towards toolkit levels is included here
float effectiveLevel = GameMath.gate(0, level() + exp/10f, 10);
partialCharge += (2 + (1f * effectiveLevel)) * levelPortion;
//charge is in increments of 1/10 max hunger value.
while (partialCharge >= 1) {
charge++;
partialCharge -= 1;
if (charge == chargeCap){
GLog.p( Messages.get(AlchemistsToolkit.class, "full") );
partialCharge = 0;
}
updateQuickslot();
}
} else
partialCharge = 0;
}
@Override
public int getEnergy() {
return charge;
}
@Override
public void spendEnergy(int reduction) {
charge = Math.max(0, charge - reduction);
}
}
public static class upgradeKit extends Recipe {
@Override
public boolean testIngredients(ArrayList<Item> ingredients) {
return ingredients.get(0) instanceof AlchemistsToolkit
&& !AlchemyScene.providerIsToolkit();
}
private static int lastCost;
@Override
public int cost(ArrayList<Item> ingredients) {
return lastCost = Math.max(1, AlchemyScene.availableEnergy());
}
@Override
public Item brew(ArrayList<Item> ingredients) {
AlchemistsToolkit existing = (AlchemistsToolkit) ingredients.get(0);
existing.absorbEnergy(lastCost);
return existing;
}
@Override
public Item sampleOutput(ArrayList<Item> ingredients) {
AlchemistsToolkit sample = new AlchemistsToolkit();
sample.identify();
AlchemistsToolkit existing = (AlchemistsToolkit) ingredients.get(0);
sample.charge = existing.charge;
sample.partialCharge = existing.partialCharge;
sample.exp = existing.exp;
sample.level(existing.level());
sample.absorbEnergy(AlchemyScene.availableEnergy());
return sample;
}
}
}
| 6,616 | AlchemistsToolkit | java | en | java | code | {"qsc_code_num_words": 728, "qsc_code_num_chars": 6616.0, "qsc_code_mean_word_length": 6.17307692, "qsc_code_frac_words_unique": 0.32554945, "qsc_code_frac_chars_top_2grams": 0.04049844, "qsc_code_frac_chars_top_3grams": 0.08455719, "qsc_code_frac_chars_top_4grams": 0.08811749, "qsc_code_frac_chars_dupe_5grams": 0.09679573, "qsc_code_frac_chars_dupe_6grams": 0.05585225, "qsc_code_frac_chars_dupe_7grams": 0.01802403, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0124808, "qsc_code_frac_chars_whitespace": 0.21281741, "qsc_code_size_file_byte": 6616.0, "qsc_code_num_lines": 250.0, "qsc_code_num_chars_line_max": 117.0, "qsc_code_num_chars_line_mean": 26.464, "qsc_code_frac_chars_alphabet": 0.85042243, "qsc_code_frac_chars_comments": 0.16550786, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.18390805, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01793153, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.0862069, "qsc_codejava_score_lines_no_logic": 0.2183908, "qsc_codejava_frac_words_no_modifier": 0.88235294, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 0.5, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/artifacts/MasterThievesArmband.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.artifacts;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.utils.Random;
public class MasterThievesArmband extends Artifact {
{
image = ItemSpriteSheet.ARTIFACT_ARMBAND;
levelCap = 10;
charge = 0;
}
private int exp = 0;
@Override
protected ArtifactBuff passiveBuff() {
return new Thievery();
}
@Override
public void charge(Hero target) {
if (charge < chargeCap){
charge += 10;
updateQuickslot();
}
}
@Override
public String desc() {
String desc = super.desc();
if ( isEquipped (Dungeon.hero) ){
if (cursed){
desc += "\n\n" + Messages.get(this, "desc_cursed");
} else {
desc += "\n\n" + Messages.get(this, "desc_worn");
}
}
return desc;
}
public class Thievery extends ArtifactBuff{
public void collect(int gold){
if (!cursed) {
charge += gold/2;
}
}
@Override
public void detach() {
charge *= 0.95;
super.detach();
}
@Override
public boolean act() {
if (cursed) {
if (Dungeon.gold > 0 && Random.Int(6) == 0){
Dungeon.gold--;
}
spend(TICK);
return true;
} else {
return super.act();
}
}
public boolean steal(int value){
if (value <= charge){
charge -= value;
exp += value;
} else {
float chance = stealChance(value);
if (Random.Float() > chance)
return false;
else {
if (chance <= 1)
charge = 0;
else
//removes the charge it took you to reach 100%
charge -= charge/chance;
exp += value;
}
}
while(exp >= (250 + 50*level()) && level() < levelCap) {
exp -= (250 + 50*level());
upgrade();
}
return true;
}
public float stealChance(int value){
//get lvl*50 gold or lvl*3.33% item value of free charge, whichever is less.
int chargeBonus = Math.min(level()*50, (value*level())/30);
return (((float)charge + chargeBonus)/value);
}
}
}
| 2,964 | MasterThievesArmband | java | en | java | code | {"qsc_code_num_words": 366, "qsc_code_num_chars": 2964.0, "qsc_code_mean_word_length": 5.30601093, "qsc_code_frac_words_unique": 0.44535519, "qsc_code_frac_chars_top_2grams": 0.04376931, "qsc_code_frac_chars_top_3grams": 0.09783728, "qsc_code_frac_chars_top_4grams": 0.09062822, "qsc_code_frac_chars_dupe_5grams": 0.06797116, "qsc_code_frac_chars_dupe_6grams": 0.0545829, "qsc_code_frac_chars_dupe_7grams": 0.02574665, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02358079, "qsc_code_frac_chars_whitespace": 0.22739541, "qsc_code_size_file_byte": 2964.0, "qsc_code_num_lines": 128.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 23.15625, "qsc_code_frac_chars_alphabet": 0.82445415, "qsc_code_frac_chars_comments": 0.30465587, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.18390805, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01358564, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09195402, "qsc_codejava_score_lines_no_logic": 0.2183908, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/series60/_obex.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
import socket as _socket
import os
import types
import _lightbluecommon
from _obexcommon import OBEXError
# public attributes
__all__ = ("sendfile", "recvfile")
def sendfile(address, channel, source):
if not isinstance(source, (types.StringTypes, types.FileType)):
raise TypeError("source must be string or built-in file object")
if isinstance(source, types.StringTypes):
try:
_socket.bt_obex_send_file(address, channel, unicode(source))
except Exception, e:
raise OBEXError(str(e))
else:
# given file object
if hasattr(source, "name"):
localpath = _tempfilename(source.name)
else:
localpath = _tempfilename()
try:
# write the source file object's data into a file, then send it
f = file(localpath, "wb")
f.write(source.read())
f.close()
try:
_socket.bt_obex_send_file(address, channel, unicode(localpath))
except Exception, e:
raise OBEXError(str(e))
finally:
# remove temporary file
if os.path.isfile(localpath):
try:
os.remove(localpath)
except Exception, e:
print "[lightblue.obex] unable to remove temporary file %s: %s" %\
(localpath, str(e))
def recvfile(sock, dest):
if not isinstance(dest, (types.StringTypes, types.FileType)):
raise TypeError("dest must be string or built-in file object")
if isinstance(dest, types.StringTypes):
_recvfile(sock, dest)
else:
# given file object
localpath = _tempfilename()
try:
# receive a file and then read it into the file object
_recvfile(sock, localpath)
recvdfile = file(localpath, "rb")
dest.write(recvdfile.read())
recvdfile.close()
finally:
# remove temporary file
if os.path.isfile(localpath):
try:
os.remove(localpath)
except Exception, e:
print "[lightblue.obex] unable to remove temporary file %s: %s" %\
(localpath, str(e))
# receives file and saves to local path
def _recvfile(sock, localpath):
# PyS60's bt_obex_receive() won't receive the file if given a file path
# that already exists (it tells the client there's a conflict error). So
# we need to handle this somehow, and preferably backup the original file
# so that we can put it back if the recv fails.
if os.path.isfile(localpath):
# if given an existing path, rename existing file
temppath = _tempfilename(localpath)
os.rename(localpath, temppath)
else:
temppath = None
try:
# receive a file (get internal _sock cos sock is our own SocketWrapper
# object)
_socket.bt_obex_receive(sock._sock, unicode(localpath))
except _socket.error, e:
try:
if temppath is not None:
# recv failed, put original file back
os.rename(temppath, localpath)
finally:
# if the renaming of the original file fails, this will still
# get raised
raise OBEXError(str(e))
else:
# recv successful, remove the original file
if temppath is not None:
os.remove(temppath)
# Must point to C:\ because can't write in start-up dir (on Z:?)
def _tempfilename(basename="C:\\lightblue_obex_received_file"):
version = 1
while os.path.isfile(basename):
version += 1
basename = basename[:-1] + str(version)
return basename | 4,585 | _obex | py | en | python | code | {"qsc_code_num_words": 554, "qsc_code_num_chars": 4585.0, "qsc_code_mean_word_length": 4.91877256, "qsc_code_frac_words_unique": 0.33935018, "qsc_code_frac_chars_top_2grams": 0.02201835, "qsc_code_frac_chars_top_3grams": 0.02348624, "qsc_code_frac_chars_top_4grams": 0.02091743, "qsc_code_frac_chars_dupe_5grams": 0.28880734, "qsc_code_frac_chars_dupe_6grams": 0.24733945, "qsc_code_frac_chars_dupe_7grams": 0.19522936, "qsc_code_frac_chars_dupe_8grams": 0.17027523, "qsc_code_frac_chars_dupe_9grams": 0.17027523, "qsc_code_frac_chars_dupe_10grams": 0.13798165, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00321337, "qsc_code_frac_chars_whitespace": 0.32126499, "qsc_code_size_file_byte": 4585.0, "qsc_code_num_lines": 127.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 36.1023622, "qsc_code_frac_chars_alphabet": 0.87242931, "qsc_code_frac_chars_comments": 0.33522356, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.47368421, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.08430136, "qsc_code_frac_chars_long_word_length": 0.01062064, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 0.0, "qsc_codepython_frac_lines_func_ratio": null, "qsc_codepython_cate_var_zero": null, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.06578947, "qsc_codepython_frac_lines_simplefunc": null, "qsc_codepython_score_lines_no_logic": null, "qsc_codepython_frac_lines_print": 0.02631579} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 1, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfCorrosion.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.CorrosiveGas;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Ooze;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.CorrosionParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.ColorMath;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
public class WandOfCorrosion extends Wand {
{
image = ItemSpriteSheet.WAND_CORROSION;
collisionProperties = Ballistica.STOP_TARGET | Ballistica.STOP_TERRAIN;
}
@Override
protected void onZap(Ballistica bolt) {
CorrosiveGas gas = Blob.seed(bolt.collisionPos, 50 + 10 * level(), CorrosiveGas.class);
CellEmitter.center(bolt.collisionPos).burst( CorrosionParticle.SPLASH, 10 );
gas.setStrength(2 + level());
GameScene.add(gas);
for (int i : PathFinder.NEIGHBOURS9) {
Char ch = Actor.findChar(bolt.collisionPos + i);
if (ch != null) {
processSoulMark(ch, chargesPerCast());
}
}
if (Actor.findChar(bolt.collisionPos) == null){
Dungeon.level.pressCell(bolt.collisionPos);
}
}
@Override
protected void fx(Ballistica bolt, Callback callback) {
MagicMissile.boltFromChar(
curUser.sprite.parent,
MagicMissile.CORROSION,
curUser.sprite,
bolt.collisionPos,
callback);
Sample.INSTANCE.play(Assets.SND_ZAP);
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
// lvl 0 - 33%
// lvl 1 - 50%
// lvl 2 - 60%
if (Random.Int( level() + 3 ) >= 2) {
Buff.affect( defender, Ooze.class ).set( 20f );
CellEmitter.center(defender.pos).burst( CorrosionParticle.SPLASH, 5 );
}
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
particle.color( ColorMath.random( 0xAAAAAA, 0xFF8800) );
particle.am = 0.6f;
particle.setLifespan( 1f );
particle.acc.set(0, 20);
particle.setSize( 0.5f, 3f );
particle.shuffleXY( 1f );
}
}
| 3,620 | WandOfCorrosion | java | en | java | code | {"qsc_code_num_words": 426, "qsc_code_num_chars": 3620.0, "qsc_code_mean_word_length": 6.50938967, "qsc_code_frac_words_unique": 0.45539906, "qsc_code_frac_chars_top_2grams": 0.06491165, "qsc_code_frac_chars_top_3grams": 0.21925712, "qsc_code_frac_chars_top_4grams": 0.23800938, "qsc_code_frac_chars_dupe_5grams": 0.20014425, "qsc_code_frac_chars_dupe_6grams": 0.09953119, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0175215, "qsc_code_frac_chars_whitespace": 0.13287293, "qsc_code_size_file_byte": 3620.0, "qsc_code_num_lines": 105.0, "qsc_code_num_chars_line_max": 90.0, "qsc_code_num_chars_line_mean": 34.47619048, "qsc_code_frac_chars_alphabet": 0.86588085, "qsc_code_frac_chars_comments": 0.22734807, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05797101, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00572041, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05797101, "qsc_codejava_score_lines_no_logic": 0.36231884, "qsc_codejava_frac_words_no_modifier": 0.8, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfFrost.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.items.Heap;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
public class WandOfFrost extends DamageWand {
{
image = ItemSpriteSheet.WAND_FROST;
}
public int min(int lvl){
return 2+lvl;
}
public int max(int lvl){
return 8+5*lvl;
}
@Override
protected void onZap(Ballistica bolt) {
Heap heap = Dungeon.level.heaps.get(bolt.collisionPos);
if (heap != null) {
heap.freeze();
}
Char ch = Actor.findChar(bolt.collisionPos);
if (ch != null){
int damage = damageRoll();
if (ch.buff(Frost.class) != null){
return; //do nothing, can't affect a frozen target
}
if (ch.buff(Chill.class) != null){
//7.5% less damage per turn of chill remaining
float chill = ch.buff(Chill.class).cooldown();
damage = (int)Math.round(damage * Math.pow(0.9f, chill));
} else {
ch.sprite.burst( 0xFF99CCFF, level() / 2 + 2 );
}
processSoulMark(ch, chargesPerCast());
ch.damage(damage, this);
if (ch.isAlive()){
if (Dungeon.level.water[ch.pos])
Buff.prolong(ch, Chill.class, 4+level());
else
Buff.prolong(ch, Chill.class, 2+level());
}
} else {
Dungeon.level.pressCell(bolt.collisionPos);
}
}
@Override
protected void fx(Ballistica bolt, Callback callback) {
MagicMissile.boltFromChar(curUser.sprite.parent,
MagicMissile.FROST,
curUser.sprite,
bolt.collisionPos,
callback);
Sample.INSTANCE.play(Assets.SND_ZAP);
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
Chill chill = defender.buff(Chill.class);
if (chill != null && Random.IntRange(2, 10) <= chill.cooldown()){
//need to delay this through an actor so that the freezing isn't broken by taking damage from the staff hit.
new FlavourBuff(){
{actPriority = VFX_PRIO;}
public boolean act() {
Buff.affect(target, Frost.class, Frost.duration(target) * Random.Float(1f, 2f));
return super.act();
}
}.attachTo(defender);
}
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
particle.color(0x88CCFF);
particle.am = 0.6f;
particle.setLifespan(2f);
float angle = Random.Float(PointF.PI2);
particle.speed.polar( angle, 2f);
particle.acc.set( 0f, 1f);
particle.setSize( 0f, 1.5f);
particle.radiateXY(Random.Float(1f));
}
}
| 4,086 | WandOfFrost | java | en | java | code | {"qsc_code_num_words": 521, "qsc_code_num_chars": 4086.0, "qsc_code_mean_word_length": 5.756238, "qsc_code_frac_words_unique": 0.43570058, "qsc_code_frac_chars_top_2grams": 0.05101701, "qsc_code_frac_chars_top_3grams": 0.17739246, "qsc_code_frac_chars_top_4grams": 0.19073024, "qsc_code_frac_chars_dupe_5grams": 0.18206069, "qsc_code_frac_chars_dupe_6grams": 0.09203068, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01444252, "qsc_code_frac_chars_whitespace": 0.15271659, "qsc_code_size_file_byte": 4086.0, "qsc_code_num_lines": 130.0, "qsc_code_num_chars_line_max": 112.0, "qsc_code_num_chars_line_mean": 31.43076923, "qsc_code_frac_chars_alphabet": 0.85181976, "qsc_code_frac_chars_comments": 0.23910915, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.06521739, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00578964, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08695652, "qsc_codejava_score_lines_no_logic": 0.2826087, "qsc_codejava_frac_words_no_modifier": 0.77777778, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfPrismaticLight.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Challenges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Light;
import com.shatteredpixel.shatteredpixeldungeon.effects.Beam;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.RainbowParticle;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.scrolls.ScrollOfMagicMapping;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.levels.Terrain;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.PathFinder;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
public class WandOfPrismaticLight extends DamageWand {
{
image = ItemSpriteSheet.WAND_PRISMATIC_LIGHT;
collisionProperties = Ballistica.MAGIC_BOLT;
}
public int min(int lvl){
return 1+lvl;
}
public int max(int lvl){
return 5+3*lvl;
}
@Override
protected void onZap(Ballistica beam) {
affectMap(beam);
if (Dungeon.level.viewDistance < 6 ){
if (Dungeon.isChallenged(Challenges.DARKNESS)){
Buff.prolong( curUser, Light.class, 2f + level());
} else {
Buff.prolong( curUser, Light.class, 10f+level()*5);
}
}
Char ch = Actor.findChar(beam.collisionPos);
if (ch != null){
processSoulMark(ch, chargesPerCast());
affectTarget(ch);
}
}
private void affectTarget(Char ch){
int dmg = damageRoll();
//three in (5+lvl) chance of failing
if (Random.Int(5+level()) >= 3) {
Buff.prolong(ch, Blindness.class, 2f + (level() * 0.333f));
ch.sprite.emitter().burst(Speck.factory(Speck.LIGHT), 6 );
}
if (ch.properties().contains(Char.Property.DEMONIC) || ch.properties().contains(Char.Property.UNDEAD)){
ch.sprite.emitter().start( ShadowParticle.UP, 0.05f, 10+level() );
Sample.INSTANCE.play(Assets.SND_BURNING);
ch.damage(Math.round(dmg*1.333f), this);
} else {
ch.sprite.centerEmitter().burst( RainbowParticle.BURST, 10+level() );
ch.damage(dmg, this);
}
}
private void affectMap(Ballistica beam){
boolean noticed = false;
for (int c: beam.subPath(0, beam.dist)){
for (int n : PathFinder.NEIGHBOURS9){
int cell = c+n;
if (Dungeon.level.discoverable[cell])
Dungeon.level.mapped[cell] = true;
int terr = Dungeon.level.map[cell];
if ((Terrain.flags[terr] & Terrain.SECRET) != 0) {
Dungeon.level.discover( cell );
GameScene.discoverTile( cell, terr );
ScrollOfMagicMapping.discover(cell);
noticed = true;
}
}
CellEmitter.center(c).burst( RainbowParticle.BURST, Random.IntRange( 1, 2 ) );
}
if (noticed)
Sample.INSTANCE.play( Assets.SND_SECRET );
GameScene.updateFog();
}
@Override
protected void fx( Ballistica beam, Callback callback ) {
curUser.sprite.parent.add(
new Beam.LightRay(curUser.sprite.center(), DungeonTilemap.raisedTileCenterToWorld(beam.collisionPos)));
callback.call();
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
//cripples enemy
Buff.prolong( defender, Cripple.class, 1f+staff.level());
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
particle.color( Random.Int( 0x1000000 ) );
particle.am = 0.5f;
particle.setLifespan(1f);
particle.speed.polar(Random.Float(PointF.PI2), 2f);
particle.setSize( 1f, 2f);
particle.radiateXY( 0.5f);
}
}
| 5,179 | WandOfPrismaticLight | java | en | java | code | {"qsc_code_num_words": 615, "qsc_code_num_chars": 5179.0, "qsc_code_mean_word_length": 6.3495935, "qsc_code_frac_words_unique": 0.39512195, "qsc_code_frac_chars_top_2grams": 0.05992318, "qsc_code_frac_chars_top_3grams": 0.21408451, "qsc_code_frac_chars_top_4grams": 0.23661972, "qsc_code_frac_chars_dupe_5grams": 0.2425096, "qsc_code_frac_chars_dupe_6grams": 0.10140845, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01511447, "qsc_code_frac_chars_whitespace": 0.13129948, "qsc_code_size_file_byte": 5179.0, "qsc_code_num_lines": 159.0, "qsc_code_num_chars_line_max": 108.0, "qsc_code_num_chars_line_mean": 32.57232704, "qsc_code_frac_chars_alphabet": 0.85285619, "qsc_code_frac_chars_comments": 0.16084186, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05454545, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00207087, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.07272727, "qsc_codejava_score_lines_no_logic": 0.31818182, "qsc_codejava_frac_words_no_modifier": 0.88888889, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/linux/lightblueobex_main.c | /*
* Copyright (c) 2009 Bea Lam. All rights reserved.
*
* This file is part of LightBlue.
*
* LightBlue is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LightBlue is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lightblueobex_main.h"
#include "lightblueobex_client.h"
#include "lightblueobex_server.h"
#include <openobex/obex.h>
#include "Python.h"
#define OBEX_HI_MASK 0xc0
#define OBEX_UNICODE 0x00
#define OBEX_BYTE_STREAM 0x40
#define OBEX_BYTE 0x80
#define OBEX_INT 0xc0
/* OBEX unicode strings are UTF-16, big-endian. */
#define OBEX_BIG_ENDIAN 1 /* for encoding/decoding unicode strings */
PyObject *lightblueobex_readheaders(obex_t *obex, obex_object_t *obj)
{
PyObject *headers;
uint8_t hi;
obex_headerdata_t hv;
uint32_t hv_size;
int r;
PyObject *value = NULL;
DEBUG("%s()\n", __func__);
headers = PyDict_New();
if (headers == NULL)
return NULL;
if (obex == NULL || obj == NULL || headers == NULL) {
DEBUG("\treadheaders() got null argument\n");
return NULL;
}
if (!PyDict_Check(headers)) {
DEBUG("\treadheaders() arg must be dict\n");
return NULL;
}
while (OBEX_ObjectGetNextHeader(obex, obj, &hi, &hv, &hv_size)) {
DEBUG("\tread header: 0x%02x\n", hi);
switch (hi & OBEX_HI_MASK) {
case OBEX_UNICODE:
{
if (hv_size < 2) {
value = PyUnicode_FromUnicode(NULL, 0);
} else {
/* hv_size-2 for 2-byte null terminator */
int byteorder = OBEX_BIG_ENDIAN;
value = PyUnicode_DecodeUTF16((const char*)hv.bs, hv_size-2,
NULL, &byteorder);
if (value == NULL) {
DEBUG("\terror reading unicode header 0x%02x\n", hi);
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear(); /* let caller set exception */
}
return NULL;
}
}
break;
}
case OBEX_BYTE_STREAM:
{
value = PyBuffer_New(hv_size);
if (value != NULL) {
void *buf;
Py_ssize_t buflen;
if (PyObject_AsWriteBuffer(value, &buf, &buflen) < 0) {
Py_DECREF(value);
DEBUG("\terror writing to buffer for header 0x%02x\n", hi);
return NULL;
}
memcpy(buf, hv.bs, buflen);
}
break;
}
case OBEX_BYTE:
{
value = PyInt_FromLong(hv.bq1);
break;
}
case OBEX_INT:
{
value = PyLong_FromUnsignedLong(hv.bq4);
break;
}
default:
DEBUG("\tunknown header id encoding %d\n", (hi & OBEX_HI_MASK));
return NULL;
}
if (value == NULL) {
if (PyErr_Occurred() == NULL)
DEBUG("\terror reading headers\n");
return NULL;
}
r = PyDict_SetItem(headers, PyInt_FromLong((long)hi), value);
Py_DECREF(value);
if (r < 0) {
DEBUG("\tPyDict_SetItem() error\n");
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear(); /* let caller set exception */
}
return NULL;
}
}
return headers;
}
static int lightblueobex_add4byteheader(obex_t *obex, obex_object_t *obj, uint8_t hi, PyObject *value)
{
obex_headerdata_t hv;
uint32_t intvalue;
DEBUG("%s()\n", __func__);
if (value == NULL)
return -1;
if (PyInt_Check(value)) {
intvalue = PyInt_AsLong(value);
if (PyErr_Occurred()) {
DEBUG("\tcan't convert header 0x%02x int value to long", hi);
PyErr_Clear();
return -1;
}
} else if (PyLong_Check(value)) {
intvalue = PyLong_AsUnsignedLong(value);
if (PyErr_Occurred()) {
DEBUG("\tcan't convert header 0x%02x long value to long", hi);
PyErr_Clear();
return -1;
}
} else {
DEBUG("\theader value for id 0x%02x must be int or long, was %s\n",
hi, value->ob_type->tp_name);
return -1;
}
hv.bq4 = intvalue;
return OBEX_ObjectAddHeader(obex, obj, hi, hv, 4, OBEX_FL_FIT_ONE_PACKET);
}
static int lightblueobex_addbytestreamheader(obex_t *obex, obex_object_t *obj, uint8_t hi, PyObject *bufObject)
{
obex_headerdata_t hv;
uint32_t hv_size;
DEBUG("%s()\n", __func__);
if (PyObject_AsReadBuffer(bufObject, (const void**)&hv.bs, (Py_ssize_t*)&hv_size) < 0) {
DEBUG("\theader value for id 0x%02x must be readable buffer\n", hi);
return -1;
}
return OBEX_ObjectAddHeader(obex, obj, hi, hv, hv_size, OBEX_FL_FIT_ONE_PACKET);
}
static int lightblueobex_addunicodeheader(obex_t *obex, obex_object_t *obj, uint8_t hi, PyObject *utf16string)
{
obex_headerdata_t hv;
Py_ssize_t len = PyUnicode_GET_SIZE(utf16string);
uint8_t bytes[len+2];
DEBUG("%s()\n", __func__);
/* need to add 2-byte null terminator */
memcpy(bytes, (const uint8_t*)PyString_AsString(utf16string), len);
bytes[len] = 0x00;
bytes[len+1] = 0x00;
hv.bs = bytes;
return OBEX_ObjectAddHeader(obex, obj, (uint8_t)hi, hv, len+2,
OBEX_FL_FIT_ONE_PACKET);
}
int lightblueobex_addheaders(obex_t *obex, PyObject *headers, obex_object_t *obj)
{
uint8_t hi;
obex_headerdata_t hv;
PyObject *key, *value;
Py_ssize_t pos = 0;
int r = -1;
DEBUG("%s()\n", __func__);
if (headers == NULL || !PyDict_Check(headers)) {
DEBUG("\taddheaders() arg must be dict\n");
return -1;
}
/* add connection-id first */
key = PyInt_FromLong(OBEX_HDR_CONNECTION);
if (key != NULL) {
value = PyDict_GetItem(headers, key); /* don't decref! */
Py_DECREF(key);
key = NULL;
if (value != NULL) {
DEBUG("\tadding connection-id\n");
r = lightblueobex_add4byteheader(obex, obj, OBEX_HDR_CONNECTION,
value);
if (r < 0) {
DEBUG("\terror adding connection-id header\n");
return -1;
}
}
}
/* add target header first (shouldn't have both conn-id and target) */
key = PyInt_FromLong(OBEX_HDR_TARGET);
if (key != NULL) {
value = PyDict_GetItem(headers, key); /* don't decref! */
Py_DECREF(key);
key = NULL;
if (value != NULL) {
DEBUG("\tadding target\n");
r = lightblueobex_addbytestreamheader(obex, obj, OBEX_HDR_TARGET,
value);
if (r < 0) {
DEBUG("\terror adding target header\n");
return -1;
}
}
}
while (PyDict_Next(headers, &pos, &key, &value)) {
if (key == NULL || value == NULL) {
DEBUG("\terror reading headers dict\n");
return -1;
}
if (!PyInt_Check(key)) {
DEBUG("\theader id must be int, was %s\n", key->ob_type->tp_name);
return -1;
}
hi = (uint8_t)PyInt_AsUnsignedLongMask(key);
if (hi == OBEX_HDR_CONNECTION || hi == OBEX_HDR_TARGET) {
/* these are already added */
continue;
}
DEBUG("\tadding header: 0x%02x\n", hi);
switch (hi & OBEX_HI_MASK) {
case OBEX_UNICODE:
{
PyObject *encoded = NULL;
if (PyUnicode_Check(value)) {
encoded = PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(value),
PyUnicode_GET_SIZE(value),
NULL, OBEX_BIG_ENDIAN);
} else {
/* try converting to unicode */
PyObject *tmp = NULL;
tmp = PyUnicode_FromObject(value);
if (tmp == NULL) {
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear(); /* let caller set exception */
}
DEBUG("\tfailed to convert header value for id 0x%02x to unicode\n", hi);
return -1;
}
encoded = PyUnicode_EncodeUTF16(PyUnicode_AS_UNICODE(tmp),
PyUnicode_GET_SIZE(tmp),
NULL, OBEX_BIG_ENDIAN);
Py_DECREF(tmp);
}
if (encoded == NULL) {
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear(); /* let caller set exception */
}
DEBUG("\tfailed to encode value for header 0x%02x to UTF-16 big endian\n", hi);
return -1;
}
r = lightblueobex_addunicodeheader(obex, obj, hi, encoded);
Py_DECREF(encoded);
break;
}
case OBEX_BYTE_STREAM:
{
r = lightblueobex_addbytestreamheader(obex, obj, hi, value);
break;
}
case OBEX_BYTE:
{
long intvalue;
if (!PyInt_Check(value)) {
DEBUG("\theader value for id 0x%02x must be int, was %s\n",
hi, value->ob_type->tp_name);
return -1;
}
intvalue = PyInt_AsLong(value);
if (PyErr_Occurred()) {
DEBUG("\terror reading int value for 0x%02x\n", hi);
PyErr_Clear();
return -1;
}
hv.bq1 = (uint8_t)intvalue;
r = OBEX_ObjectAddHeader(obex, obj, hi, hv, 1,
OBEX_FL_FIT_ONE_PACKET);
break;
}
case OBEX_INT:
{
r = lightblueobex_add4byteheader(obex, obj, hi, value);
break;
}
default:
DEBUG("\tunknown header id encoding %d\n", (hi & OBEX_HI_MASK));
return -1;
}
if (r < 0) {
DEBUG("\terror adding header 0x%02x\n", hi);
return -1;
}
}
return 1;
}
PyObject *lightblueobex_filetostream(obex_t *obex, obex_object_t *obj, PyObject *fileobj, int bufsize)
{
const void *data;
Py_ssize_t datalen; /* or unsigned int? */
obex_headerdata_t hv;
PyObject *buf;
DEBUG("%s()\n", __func__);
if (fileobj == NULL) {
DEBUG("\tgiven file object is NULL\n");
hv.bs = NULL;
OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hv, 0,
OBEX_FL_STREAM_DATAEND);
return NULL;
}
buf = PyObject_CallMethod(fileobj, "read", "i", bufsize);
if (buf == NULL) {
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear(); /* let caller set exception */
}
DEBUG("\terror calling file object read()\n");
}
if (buf != NULL && !PyObject_CheckReadBuffer(buf)) {
DEBUG("\tfile object read() returned non-buffer object\n");
Py_DECREF(buf);
buf = NULL;
}
if (buf != NULL && PyObject_AsReadBuffer(buf, &data, &datalen) < 0) {
DEBUG("\terror reading file object contents\n");
Py_DECREF(buf);
buf = NULL;
}
if (buf == NULL) {
hv.bs = NULL;
OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hv, 0,
OBEX_FL_STREAM_DATAEND);
return NULL;
}
hv.bs = (uint8_t*)data;
if (OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hv, datalen,
(datalen == 0 ? OBEX_FL_STREAM_DATAEND : OBEX_FL_STREAM_DATA)) < 0) {
DEBUG("\terror adding body data\n");
Py_DECREF(buf);
buf = NULL;
}
return buf;
}
int lightblueobex_streamtofile(obex_t *obex, obex_object_t *obj, PyObject *fileobj)
{
const uint8_t *buf;
int buflen;
DEBUG("%s()\n", __func__);
if (fileobj == NULL)
return -1;
buflen = OBEX_ObjectReadStream(obex, obj, &buf);
if (buflen == 0)
return 0;
if (buflen < 0) {
DEBUG("\tunable to read body data from request\n");
return -1;
}
DEBUG("\treading %d bytes\n", buflen);
PyObject *pybuf = PyBuffer_FromMemory((void*)buf, buflen);
if (pybuf == NULL) {
DEBUG("\terror reading received body\n");
return -1;
}
PyObject *result = PyObject_CallMethod(fileobj, "write", "O", pybuf);
Py_DECREF(pybuf);
if (result == NULL) {
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear(); /* let caller set exception */
}
DEBUG("error calling write() on file object\n");
return -1;
}
Py_DECREF(result);
return buflen;
}
static PyMethodDef module_methods[] = {
{NULL} /* Sentinel */
};
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
init_lightblueobex(void)
{
PyObject *m;
PyTypeObject *clientType;
PyTypeObject *serverType;
clientType = lightblueobex_getclienttype();
serverType = lightblueobex_getservertype();
if ( (PyType_Ready(clientType) < 0) ||
(PyType_Ready(serverType) < 0) ) {
return;
}
m = Py_InitModule3("_lightblueobex", module_methods,
"Module containing the OBEXClient and OBEXServer classes.");
if (m == NULL)
return;
PyModule_AddIntConstant(m, "CONNECT", 0x00);
PyModule_AddIntConstant(m, "DISCONNECT", 0x01);
PyModule_AddIntConstant(m, "PUT", 0x02);
PyModule_AddIntConstant(m, "GET", 0x03);
PyModule_AddIntConstant(m, "SETPATH", 0x05);
PyModule_AddIntConstant(m, "SESSION", 0x07);
PyModule_AddIntConstant(m, "ABORT", 0x7f);
/* or should these constants be in the linux obex module? */
PyModule_AddIntConstant(m, "COUNT", 0xc0);
PyModule_AddIntConstant(m, "NAME", 0x01);
PyModule_AddIntConstant(m, "TYPE", 0x42);
PyModule_AddIntConstant(m, "LENGTH", 0xc3);
PyModule_AddIntConstant(m, "TIME", 0x44);
PyModule_AddIntConstant(m, "DESCRIPTION", 0x05);
PyModule_AddIntConstant(m, "TARGET", 0x46);
PyModule_AddIntConstant(m, "HTTP", 0x47);
PyModule_AddIntConstant(m, "BODY", 0x48);
PyModule_AddIntConstant(m, "END_OF_BODY", 0x49);
PyModule_AddIntConstant(m, "WHO", 0x4a);
PyModule_AddIntConstant(m, "CONNECTION_ID", 0xcb);
PyModule_AddIntConstant(m, "APP_PARAMETERS", 0x4c);
PyModule_AddIntConstant(m, "AUTH_CHALLENGE", 0x4d);
PyModule_AddIntConstant(m, "AUTH_RESPONSE", 0x4e);
PyModule_AddIntConstant(m, "CREATOR", 0xcf);
PyModule_AddIntConstant(m, "WAN_UUID", 0x50);
PyModule_AddIntConstant(m, "OBJECT_CLASS", 0x51);
PyModule_AddIntConstant(m, "SESSION_PARAMETERS", 0x52);
PyModule_AddIntConstant(m, "SESSION_SEQUENCE_NUMBER", 0x93);
PyModule_AddIntConstant(m, "CONTINUE", 0x10);
PyModule_AddIntConstant(m, "SWITCH_PRO", 0x11);
PyModule_AddIntConstant(m, "SUCCESS", 0x20);
PyModule_AddIntConstant(m, "CREATED", 0x21);
PyModule_AddIntConstant(m, "ACCEPTED", 0x22);
PyModule_AddIntConstant(m, "NON_AUTHORITATIVE", 0x23);
PyModule_AddIntConstant(m, "NO_CONTENT", 0x24);
PyModule_AddIntConstant(m, "RESET_CONTENT", 0x25);
PyModule_AddIntConstant(m, "PARTIAL_CONTENT", 0x26);
PyModule_AddIntConstant(m, "MULTIPLE_CHOICES", 0x30);
PyModule_AddIntConstant(m, "MOVED_PERMANENTLY", 0x31);
PyModule_AddIntConstant(m, "MOVED_TEMPORARILY", 0x32);
PyModule_AddIntConstant(m, "SEE_OTHER", 0x33);
PyModule_AddIntConstant(m, "NOT_MODIFIED", 0x34);
PyModule_AddIntConstant(m, "USE_PROXY", 0x35);
PyModule_AddIntConstant(m, "BAD_REQUEST", 0x40);
PyModule_AddIntConstant(m, "UNAUTHORIZED", 0x41);
PyModule_AddIntConstant(m, "PAYMENT_REQUIRED", 0x42);
PyModule_AddIntConstant(m, "FORBIDDEN", 0x43);
PyModule_AddIntConstant(m, "NOT_FOUND", 0x44);
PyModule_AddIntConstant(m, "METHOD_NOT_ALLOWED", 0x45);
PyModule_AddIntConstant(m, "NOT_ACCEPTABLE", 0x46);
PyModule_AddIntConstant(m, "PROXY_AUTH_REQUIRED", 0x47);
PyModule_AddIntConstant(m, "REQUEST_TIME_OUT", 0x48);
PyModule_AddIntConstant(m, "CONFLICT", 0x49);
PyModule_AddIntConstant(m, "GONE", 0x4a);
PyModule_AddIntConstant(m, "LENGTH_REQUIRED", 0x4b);
PyModule_AddIntConstant(m, "PRECONDITION_FAILED", 0x4c);
PyModule_AddIntConstant(m, "REQ_ENTITY_TOO_LARGE", 0x4d);
PyModule_AddIntConstant(m, "REQ_URL_TOO_LARGE", 0x4e);
PyModule_AddIntConstant(m, "UNSUPPORTED_MEDIA_TYPE", 0x4f);
PyModule_AddIntConstant(m, "INTERNAL_SERVER_ERROR", 0x50);
PyModule_AddIntConstant(m, "NOT_IMPLEMENTED", 0x51);
PyModule_AddIntConstant(m, "BAD_GATEWAY", 0x52);
PyModule_AddIntConstant(m, "SERVICE_UNAVAILABLE", 0x53);
PyModule_AddIntConstant(m, "GATEWAY_TIMEOUT", 0x54);
PyModule_AddIntConstant(m, "VERSION_NOT_SUPPORTED", 0x55);
PyModule_AddIntConstant(m, "DATABASE_FULL", 0x60);
PyModule_AddIntConstant(m, "DATABASE_LOCKED", 0x61);
Py_INCREF(clientType);
PyModule_AddObject(m, "OBEXClient", (PyObject *)clientType);
Py_INCREF(serverType);
PyModule_AddObject(m, "OBEXServer", (PyObject *)serverType);
}
| 17,841 | lightblueobex_main | c | en | c | code | {"qsc_code_num_words": 1999, "qsc_code_num_chars": 17841.0, "qsc_code_mean_word_length": 4.9849925, "qsc_code_frac_words_unique": 0.21510755, "qsc_code_frac_chars_top_2grams": 0.14570998, "qsc_code_frac_chars_top_3grams": 0.15233317, "qsc_code_frac_chars_top_4grams": 0.00983442, "qsc_code_frac_chars_dupe_5grams": 0.30687406, "qsc_code_frac_chars_dupe_6grams": 0.24124436, "qsc_code_frac_chars_dupe_7grams": 0.20351229, "qsc_code_frac_chars_dupe_8grams": 0.18153537, "qsc_code_frac_chars_dupe_9grams": 0.15413949, "qsc_code_frac_chars_dupe_10grams": 0.13075765, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02701836, "qsc_code_frac_chars_whitespace": 0.30088, "qsc_code_size_file_byte": 17841.0, "qsc_code_num_lines": 556.0, "qsc_code_num_chars_line_max": 112.0, "qsc_code_num_chars_line_mean": 32.0881295, "qsc_code_frac_chars_alphabet": 0.77190732, "qsc_code_frac_chars_comments": 0.0797601, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.30786026, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.1372967, "qsc_code_frac_chars_long_word_length": 0.00797953, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.01778644, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codec_frac_lines_func_ratio": 0.03056769, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 0.0, "qsc_codec_score_lines_no_logic": 0.08296943, "qsc_codec_frac_lines_print": 0.0, "qsc_codec_frac_lines_preprocessor_directives": 0.03056769} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 0, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/linux/lightblue_util.c | /*
* Copyright (c) 2009 Bea Lam. All rights reserved.
*
* This file is part of LightBlue.
*
* LightBlue is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LightBlue is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Extension module to access BlueZ operations not provided in PyBluez.
*/
#include "Python.h"
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
/*
* Returns name of local device
*/
static PyObject* lb_hci_read_local_name(PyObject *self, PyObject *args)
{
int err = 0;
int timeout = 0;
int fd = 0;
char name[249];
if (!PyArg_ParseTuple(args, "ii", &fd, &timeout))
return NULL;
Py_BEGIN_ALLOW_THREADS
err = hci_read_local_name(fd, sizeof(name)-1, name, timeout);
Py_END_ALLOW_THREADS
if (err != 0)
return PyErr_SetFromErrno(PyExc_IOError);
return PyString_FromString(name);
}
/*
* Returns address of local device
*/
static PyObject* lb_hci_read_bd_addr(PyObject *self, PyObject *args)
{
int err = 0;
int timeout = 0;
int fd = 0;
bdaddr_t ba;
char addrstr[19] = {0};
if (!PyArg_ParseTuple(args, "ii", &fd, &timeout))
return NULL;
Py_BEGIN_ALLOW_THREADS
err = hci_read_bd_addr(fd, &ba, timeout);
Py_END_ALLOW_THREADS
if (err != 0)
return PyErr_SetFromErrno(PyExc_IOError);
ba2str(&ba, addrstr);
return PyString_FromString(addrstr);
}
/*
* Returns class of device of local device as a
* (service, major, minor) tuple
*/
static PyObject* lb_hci_read_class_of_dev(PyObject *self, PyObject *args)
{
int err = 0;
int timeout = 0;
int fd = 0;
uint8_t cod[3];
if (!PyArg_ParseTuple(args, "ii", &fd, &timeout))
return NULL;
Py_BEGIN_ALLOW_THREADS
err = hci_read_class_of_dev(fd, cod, timeout);
Py_END_ALLOW_THREADS
if (err != 0)
return PyErr_SetFromErrno(PyExc_IOError);
return Py_BuildValue("(B,B,B)", cod[2] << 3, cod[1] & 0x1f, cod[0] >> 2);
}
/* list of all functions in this module */
static PyMethodDef utilmethods[] = {
{"hci_read_local_name", lb_hci_read_local_name, METH_VARARGS },
{"hci_read_bd_addr", lb_hci_read_bd_addr, METH_VARARGS},
{"hci_read_class_of_dev", lb_hci_read_class_of_dev, METH_VARARGS},
{ NULL, NULL } /* sentinel */
};
/* module initialization functions */
void init_lightblueutil(void) {
Py_InitModule("_lightblueutil", utilmethods);
}
| 2,986 | lightblue_util | c | en | c | code | {"qsc_code_num_words": 427, "qsc_code_num_chars": 2986.0, "qsc_code_mean_word_length": 4.54566745, "qsc_code_frac_words_unique": 0.3676815, "qsc_code_frac_chars_top_2grams": 0.04327666, "qsc_code_frac_chars_top_3grams": 0.02782071, "qsc_code_frac_chars_top_4grams": 0.03297269, "qsc_code_frac_chars_dupe_5grams": 0.43534261, "qsc_code_frac_chars_dupe_6grams": 0.3760948, "qsc_code_frac_chars_dupe_7grams": 0.32766615, "qsc_code_frac_chars_dupe_8grams": 0.32766615, "qsc_code_frac_chars_dupe_9grams": 0.29057187, "qsc_code_frac_chars_dupe_10grams": 0.29057187, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01451131, "qsc_code_frac_chars_whitespace": 0.21533825, "qsc_code_size_file_byte": 2986.0, "qsc_code_num_lines": 113.0, "qsc_code_num_chars_line_max": 78.0, "qsc_code_num_chars_line_mean": 26.42477876, "qsc_code_frac_chars_alphabet": 0.81391379, "qsc_code_frac_chars_comments": 0.3596785, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.45, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.04759414, "qsc_code_frac_chars_long_word_length": 0.01098326, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00209205, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codec_frac_lines_func_ratio": 0.16666667, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 0.0, "qsc_codec_score_lines_no_logic": 0.28333333, "qsc_codec_frac_lines_print": 0.0, "qsc_codec_frac_lines_preprocessor_directives": 0.06666667} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 0, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/linux/lightblueobex_main.h | /*
* Copyright (c) 2009 Bea Lam. All rights reserved.
*
* This file is part of LightBlue.
*
* LightBlue is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LightBlue is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LIGHTBLUEOBEX_MAIN_H
#define LIGHTBLUEOBEX_MAIN_H
#include "Python.h"
#include <openobex/obex.h>
/* compatibility with python versions before 2.5 (PEP 353) */
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif
#ifndef LIGHTBLUE_DEBUG
#define LIGHTBLUE_DEBUG 0
#endif
#if LIGHTBLUE_DEBUG
#define DEBUG(format, args...) fprintf(stderr, format, ##args)
#else
#define DEBUG(format, args...)
#endif
PyObject *lightblueobex_readheaders(obex_t *obex, obex_object_t *obj);
int lightblueobex_addheaders(obex_t *obex, PyObject *headers, obex_object_t *obj);
PyObject *lightblueobex_filetostream(obex_t *obex, obex_object_t *obj, PyObject *fileobj, int bufsize);
int lightblueobex_streamtofile(obex_t *obex, obex_object_t *obj, PyObject *fileobj);
#endif
| 1,602 | lightblueobex_main | h | en | c | code | {"qsc_code_num_words": 243, "qsc_code_num_chars": 1602.0, "qsc_code_mean_word_length": 4.88477366, "qsc_code_frac_words_unique": 0.48971193, "qsc_code_frac_chars_top_2grams": 0.02358888, "qsc_code_frac_chars_top_3grams": 0.02695872, "qsc_code_frac_chars_top_4grams": 0.04717776, "qsc_code_frac_chars_dupe_5grams": 0.17101938, "qsc_code_frac_chars_dupe_6grams": 0.1305813, "qsc_code_frac_chars_dupe_7grams": 0.08340354, "qsc_code_frac_chars_dupe_8grams": 0.06402696, "qsc_code_frac_chars_dupe_9grams": 0.06402696, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01468429, "qsc_code_frac_chars_whitespace": 0.14981273, "qsc_code_size_file_byte": 1602.0, "qsc_code_num_lines": 53.0, "qsc_code_num_chars_line_max": 104.0, "qsc_code_num_chars_line_mean": 30.22641509, "qsc_code_frac_chars_alphabet": 0.85682819, "qsc_code_frac_chars_comments": 0.4968789, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.18181818, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00992556, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.01240695, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codec_frac_lines_func_ratio": 0.27272727, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 0.0, "qsc_codec_score_lines_no_logic": 0.36363636, "qsc_codec_frac_lines_print": 0.04545455, "qsc_codec_frac_lines_preprocessor_directives": null} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 1, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfCorruption.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Badges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Amok;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Bleeding;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Blindness;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Charm;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Chill;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Corrosion;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Corruption;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Cripple;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Doom;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Drowsy;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.FlavourBuff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.MagicalSleep;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Ooze;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.PinCushion;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Roots;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Slow;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.SoulMark;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Terror;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Vertigo;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Weakness;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Bee;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.King;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mimic;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Piranha;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Statue;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Swarm;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Wraith;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Yog;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.Random;
import java.util.HashMap;
//TODO need to consider other balance adjustments here. Might want to put more emphasis into debuffs rather than less
public class WandOfCorruption extends Wand {
{
image = ItemSpriteSheet.WAND_CORRUPTION;
}
//Note that some debuffs here have a 0% chance to be applied.
// This is because the wand of corruption considers them to be a certain level of harmful
// for the purposes of reducing resistance, but does not actually apply them itself
private static final float MINOR_DEBUFF_WEAKEN = 7/8f;
private static final HashMap<Class<? extends Buff>, Float> MINOR_DEBUFFS = new HashMap<>();
static{
MINOR_DEBUFFS.put(Weakness.class, 2f);
MINOR_DEBUFFS.put(Cripple.class, 1f);
MINOR_DEBUFFS.put(Blindness.class, 1f);
MINOR_DEBUFFS.put(Terror.class, 1f);
MINOR_DEBUFFS.put(Chill.class, 0f);
MINOR_DEBUFFS.put(Ooze.class, 0f);
MINOR_DEBUFFS.put(Roots.class, 0f);
MINOR_DEBUFFS.put(Vertigo.class, 0f);
MINOR_DEBUFFS.put(Drowsy.class, 0f);
MINOR_DEBUFFS.put(Bleeding.class, 0f);
MINOR_DEBUFFS.put(Burning.class, 0f);
MINOR_DEBUFFS.put(Poison.class, 0f);
}
private static final float MAJOR_DEBUFF_WEAKEN = 4/5f;
private static final HashMap<Class<? extends Buff>, Float> MAJOR_DEBUFFS = new HashMap<>();
static{
MAJOR_DEBUFFS.put(Amok.class, 3f);
MAJOR_DEBUFFS.put(Slow.class, 2f);
MAJOR_DEBUFFS.put(Paralysis.class, 1f);
MAJOR_DEBUFFS.put(Charm.class, 0f);
MAJOR_DEBUFFS.put(MagicalSleep.class, 0f);
MAJOR_DEBUFFS.put(SoulMark.class, 0f);
MAJOR_DEBUFFS.put(Corrosion.class, 0f);
MAJOR_DEBUFFS.put(Frost.class, 0f);
MAJOR_DEBUFFS.put(Doom.class, 0f);
}
@Override
protected void onZap(Ballistica bolt) {
Char ch = Actor.findChar(bolt.collisionPos);
if (ch != null){
if (!(ch instanceof Mob)){
return;
}
Mob enemy = (Mob) ch;
float corruptingPower = 3 + level()/2;
//base enemy resistance is usually based on their exp, but in special cases it is based on other criteria
float enemyResist = 1 + enemy.EXP;
if (ch instanceof Mimic || ch instanceof Statue){
enemyResist = 1 + Dungeon.depth;
} else if (ch instanceof Piranha || ch instanceof Bee) {
enemyResist = 1 + Dungeon.depth/2f;
} else if (ch instanceof Wraith) {
//divide by 3 as wraiths are always at full HP and are therefore ~3x harder to corrupt
enemyResist = (1f + Dungeon.depth/3f) / 3f;
} else if (ch instanceof Yog.BurningFist || ch instanceof Yog.RottingFist) {
enemyResist = 1 + 30;
} else if (ch instanceof Yog.Larva || ch instanceof King.Undead){
enemyResist = 1 + 5;
} else if (ch instanceof Swarm){
//child swarms don't give exp, so we force this here.
enemyResist = 1 + 3;
}
//100% health: 3x resist 75%: 2.1x resist 50%: 1.5x resist 25%: 1.1x resist
enemyResist *= 1 + 2*Math.pow(enemy.HP/(float)enemy.HT, 2);
//debuffs placed on the enemy reduce their resistance
for (Buff buff : enemy.buffs()){
if (MAJOR_DEBUFFS.containsKey(buff.getClass())) enemyResist *= MAJOR_DEBUFF_WEAKEN;
else if (MINOR_DEBUFFS.containsKey(buff.getClass())) enemyResist *= MINOR_DEBUFF_WEAKEN;
else if (buff.type == Buff.buffType.NEGATIVE) enemyResist *= MINOR_DEBUFF_WEAKEN;
}
//cannot re-corrupt or doom an enemy, so give them a major debuff instead
if(enemy.buff(Corruption.class) != null || enemy.buff(Doom.class) != null){
corruptingPower = enemyResist - 0.001f;
}
if (corruptingPower > enemyResist){
corruptEnemy( enemy );
} else {
float debuffChance = corruptingPower / enemyResist;
if (Random.Float() < debuffChance){
debuffEnemy( enemy, MAJOR_DEBUFFS);
} else {
debuffEnemy( enemy, MINOR_DEBUFFS);
}
}
processSoulMark(ch, chargesPerCast());
} else {
Dungeon.level.pressCell(bolt.collisionPos);
}
}
private void debuffEnemy( Mob enemy, HashMap<Class<? extends Buff>, Float> category ){
//do not consider buffs which are already assigned, or that the enemy is immune to.
HashMap<Class<? extends Buff>, Float> debuffs = new HashMap<>(category);
for (Buff existing : enemy.buffs()){
if (debuffs.containsKey(existing.getClass())) {
debuffs.put(existing.getClass(), 0f);
}
}
for (Class<?extends Buff> toAssign : debuffs.keySet()){
if (debuffs.get(toAssign) > 0 && enemy.isImmune(toAssign)){
debuffs.put(toAssign, 0f);
}
}
//all buffs with a > 0 chance are flavor buffs
Class<?extends FlavourBuff> debuffCls = (Class<? extends FlavourBuff>) Random.chances(debuffs);
if (debuffCls != null){
Buff.append(enemy, debuffCls, 6 + level()*3);
} else {
//if no debuff can be applied (all are present), then go up one tier
if (category == MINOR_DEBUFFS) debuffEnemy( enemy, MAJOR_DEBUFFS);
else if (category == MAJOR_DEBUFFS) corruptEnemy( enemy );
}
}
private void corruptEnemy( Mob enemy ){
//cannot re-corrupt or doom an enemy, so give them a major debuff instead
if(enemy.buff(Corruption.class) != null || enemy.buff(Doom.class) != null){
GLog.w( Messages.get(this, "already_corrupted") );
return;
}
if (!enemy.isImmune(Corruption.class)){
enemy.HP = enemy.HT;
for (Buff buff : enemy.buffs()) {
if (buff.type == Buff.buffType.NEGATIVE
&& !(buff instanceof SoulMark)) {
buff.detach();
} else if (buff instanceof PinCushion){
buff.detach();
}
}
if (enemy.alignment == Char.Alignment.ENEMY){
enemy.rollToDropLoot();
}
Buff.affect(enemy, Corruption.class);
Statistics.enemiesSlain++;
Badges.validateMonstersSlain();
Statistics.qualifiedForNoKilling = false;
if (enemy.EXP > 0 && curUser.lvl <= enemy.maxLvl) {
curUser.sprite.showStatus(CharSprite.POSITIVE, Messages.get(enemy, "exp", enemy.EXP));
curUser.earnExp(enemy.EXP, enemy.getClass());
} else {
curUser.earnExp(0, enemy.getClass());
}
} else {
Buff.affect(enemy, Doom.class);
}
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
// lvl 0 - 25%
// lvl 1 - 40%
// lvl 2 - 50%
if (Random.Int( level() + 4 ) >= 3){
Buff.prolong( defender, Amok.class, 4+level()*2);
}
}
@Override
protected void fx(Ballistica bolt, Callback callback) {
MagicMissile.boltFromChar( curUser.sprite.parent,
MagicMissile.SHADOW,
curUser.sprite,
bolt.collisionPos,
callback);
Sample.INSTANCE.play( Assets.SND_ZAP );
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
particle.color( 0 );
particle.am = 0.6f;
particle.setLifespan(2f);
particle.speed.set(0, 5);
particle.setSize( 0.5f, 2f);
particle.shuffleXY(1f);
}
}
| 11,018 | WandOfCorruption | java | en | java | code | {"qsc_code_num_words": 1329, "qsc_code_num_chars": 11018.0, "qsc_code_mean_word_length": 6.07599699, "qsc_code_frac_words_unique": 0.26636569, "qsc_code_frac_chars_top_2grams": 0.05572755, "qsc_code_frac_chars_top_3grams": 0.22588235, "qsc_code_frac_chars_top_4grams": 0.25609907, "qsc_code_frac_chars_dupe_5grams": 0.38798762, "qsc_code_frac_chars_dupe_6grams": 0.28866873, "qsc_code_frac_chars_dupe_7grams": 0.03839009, "qsc_code_frac_chars_dupe_8grams": 0.03839009, "qsc_code_frac_chars_dupe_9grams": 0.0269969, "qsc_code_frac_chars_dupe_10grams": 0.0269969, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01237491, "qsc_code_frac_chars_whitespace": 0.15656199, "qsc_code_size_file_byte": 11018.0, "qsc_code_num_lines": 279.0, "qsc_code_num_chars_line_max": 118.0, "qsc_code_num_chars_line_mean": 39.49103943, "qsc_code_frac_chars_alphabet": 0.8565587, "qsc_code_frac_chars_comments": 0.17190053, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.09569378, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00219202, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.00358423, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.02870813, "qsc_codejava_score_lines_no_logic": 0.28708134, "qsc_codejava_frac_words_no_modifier": 0.85714286, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfMagicMissile.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Recharging;
import com.shatteredpixel.shatteredpixeldungeon.effects.SpellSprite;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
public class WandOfMagicMissile extends DamageWand {
{
image = ItemSpriteSheet.WAND_MAGIC_MISSILE;
}
public int min(int lvl){
return 2+lvl;
}
public int max(int lvl){
return 8+2*lvl;
}
@Override
protected void onZap( Ballistica bolt ) {
Char ch = Actor.findChar( bolt.collisionPos );
if (ch != null) {
processSoulMark(ch, chargesPerCast());
ch.damage(damageRoll(), this);
ch.sprite.burst(0xFFFFFFFF, level() / 2 + 2);
} else {
Dungeon.level.pressCell(bolt.collisionPos);
}
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
Buff.prolong( attacker, Recharging.class, 1 + staff.level()/2f);
SpellSprite.show(attacker, SpellSprite.CHARGE);
}
protected int initialCharges() {
return 3;
}
}
| 2,248 | WandOfMagicMissile | java | en | java | code | {"qsc_code_num_words": 277, "qsc_code_num_chars": 2248.0, "qsc_code_mean_word_length": 6.18411552, "qsc_code_frac_words_unique": 0.5198556, "qsc_code_frac_chars_top_2grams": 0.0992411, "qsc_code_frac_chars_top_3grams": 0.22183304, "qsc_code_frac_chars_top_4grams": 0.23117338, "qsc_code_frac_chars_dupe_5grams": 0.17046118, "qsc_code_frac_chars_dupe_6grams": 0.09690601, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01356286, "qsc_code_frac_chars_whitespace": 0.14724199, "qsc_code_size_file_byte": 2248.0, "qsc_code_num_lines": 74.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 30.37837838, "qsc_code_frac_chars_alphabet": 0.88002087, "qsc_code_frac_chars_comments": 0.34741993, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00681663, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.125, "qsc_codejava_score_lines_no_logic": 0.4, "qsc_codejava_frac_words_no_modifier": 0.83333333, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfDisintegration.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.effects.Beam;
import com.shatteredpixel.shatteredpixeldungeon.effects.CellEmitter;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.PurpleParticle;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.utils.Callback;
import com.watabou.utils.Random;
import java.util.ArrayList;
public class WandOfDisintegration extends DamageWand {
{
image = ItemSpriteSheet.WAND_DISINTEGRATION;
collisionProperties = Ballistica.WONT_STOP;
}
public int min(int lvl){
return 2+lvl;
}
public int max(int lvl){
return 8+4*lvl;
}
@Override
protected void onZap( Ballistica beam ) {
boolean terrainAffected = false;
int level = level();
int maxDistance = Math.min(distance(), beam.dist);
ArrayList<Char> chars = new ArrayList<>();
int terrainPassed = 2, terrainBonus = 0;
for (int c : beam.subPath(1, maxDistance)) {
Char ch;
if ((ch = Actor.findChar( c )) != null) {
//we don't want to count passed terrain after the last enemy hit. That would be a lot of bonus levels.
//terrainPassed starts at 2, equivalent of rounding up when /3 for integer arithmetic.
terrainBonus += terrainPassed/3;
terrainPassed = terrainPassed%3;
chars.add( ch );
}
if (Dungeon.level.flamable[c]) {
Dungeon.level.destroy( c );
GameScene.updateMap( c );
terrainAffected = true;
}
if (Dungeon.level.solid[c])
terrainPassed++;
CellEmitter.center( c ).burst( PurpleParticle.BURST, Random.IntRange( 1, 2 ) );
}
if (terrainAffected) {
Dungeon.observe();
}
int lvl = level + (chars.size()-1) + terrainBonus;
for (Char ch : chars) {
processSoulMark(ch, chargesPerCast());
ch.damage( damageRoll(lvl), this );
ch.sprite.centerEmitter().burst( PurpleParticle.BURST, Random.IntRange( 1, 2 ) );
ch.sprite.flash();
}
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
//no direct effect, see magesStaff.reachfactor
}
private int distance() {
return level()*2 + 4;
}
@Override
protected void fx( Ballistica beam, Callback callback ) {
int cell = beam.path.get(Math.min(beam.dist, distance()));
curUser.sprite.parent.add(new Beam.DeathRay(curUser.sprite.center(), DungeonTilemap.raisedTileCenterToWorld( cell )));
callback.call();
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
particle.color(0x220022);
particle.am = 0.6f;
particle.setLifespan(1f);
particle.acc.set(10, -10);
particle.setSize( 0.5f, 3f);
particle.shuffleXY(1f);
}
}
| 3,952 | WandOfDisintegration | java | en | java | code | {"qsc_code_num_words": 480, "qsc_code_num_chars": 3952.0, "qsc_code_mean_word_length": 6.0375, "qsc_code_frac_words_unique": 0.47083333, "qsc_code_frac_chars_top_2grams": 0.04037267, "qsc_code_frac_chars_top_3grams": 0.1573499, "qsc_code_frac_chars_top_4grams": 0.16701173, "qsc_code_frac_chars_dupe_5grams": 0.14320221, "qsc_code_frac_chars_dupe_6grams": 0.04692892, "qsc_code_frac_chars_dupe_7grams": 0.02760524, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01569574, "qsc_code_frac_chars_whitespace": 0.16169028, "qsc_code_size_file_byte": 3952.0, "qsc_code_num_lines": 135.0, "qsc_code_num_chars_line_max": 121.0, "qsc_code_num_chars_line_mean": 29.27407407, "qsc_code_frac_chars_alphabet": 0.85904014, "qsc_code_frac_chars_comments": 0.25683198, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04878049, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00272387, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.09756098, "qsc_codejava_score_lines_no_logic": 0.29268293, "qsc_codejava_frac_words_no_modifier": 0.77777778, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/linux/_obex.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
import types
import datetime
import _lightbluecommon
import _obexcommon
import _lightblueobex # python extension
from _obexcommon import OBEXError
_HEADER_MASK = 0xc0
_HEADER_UNICODE = 0x00
_HEADER_BYTE_SEQ = 0x40
_HEADER_1BYTE = 0x80
_HEADER_4BYTE = 0xc0
# public attributes
__all__ = ("sendfile", "recvfile", "OBEXClient")
class OBEXClient(object):
__doc__ = _obexcommon._obexclientclassdoc
def __init__(self, address, channel):
if not isinstance(address, types.StringTypes):
raise TypeError("address must be string, was %s" % type(address))
if not type(channel) == int:
raise TypeError("channel must be int, was %s" % type(channel))
self.__sock = None
self.__client = None
self.__serveraddr = (address, channel)
self.__connectionid = None
def connect(self, headers={}):
if self.__client is None:
self.__setUp()
try:
resp = self.__client.request(_lightblueobex.CONNECT,
self.__convertheaders(headers), None)
except IOError, e:
raise OBEXError(str(e))
result = self.__createresponse(resp)
if result.code == _obexcommon.OK:
self.__connectionid = result.headers.get("connection-id", None)
else:
self.__closetransport()
return result
def disconnect(self, headers={}):
self.__checkconnected()
try:
try:
resp = self.__client.request(_lightblueobex.DISCONNECT,
self.__convertheaders(headers), None)
except IOError, e:
raise OBEXError(str(e))
finally:
# close bt connection regardless of disconnect response
self.__closetransport()
return self.__createresponse(resp)
def put(self, headers, fileobj):
if not hasattr(fileobj, "read"):
raise TypeError("file-like object must have read() method")
self.__checkconnected()
try:
resp = self.__client.request(_lightblueobex.PUT,
self.__convertheaders(headers), None, fileobj)
except IOError, e:
raise OBEXError(str(e))
return self.__createresponse(resp)
def delete(self, headers):
self.__checkconnected()
try:
resp = self.__client.request(_lightblueobex.PUT,
self.__convertheaders(headers), None)
except IOError, e:
raise OBEXError(str(e))
return self.__createresponse(resp)
def get(self, headers, fileobj):
if not hasattr(fileobj, "write"):
raise TypeError("file-like must have write() method")
self.__checkconnected()
try:
resp = self.__client.request(_lightblueobex.GET,
self.__convertheaders(headers), None, fileobj)
except IOError, e:
raise OBEXError(str(e))
return self.__createresponse(resp)
def setpath(self, headers, cdtoparent=False, createdirs=False):
self.__checkconnected()
flags = 0
if cdtoparent:
flags |= 1
if not createdirs:
flags |= 2
import array
setpathdata = array.array('B', (flags, 0)) # zero for constants byte
try:
resp = self.__client.request(_lightblueobex.SETPATH,
self.__convertheaders(headers), buffer(setpathdata))
except IOError, e:
raise OBEXError(str(e))
return self.__createresponse(resp)
def __setUp(self):
if self.__client is None:
import bluetooth
self.__sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
try:
self.__sock.connect((self.__serveraddr[0],
self.__serveraddr[1]))
except bluetooth.BluetoothError, e:
raise OBEXError(str(e))
try:
self.__client = _lightblueobex.OBEXClient(self.__sock.fileno())
except IOError, e:
raise OBEXError(str(e))
def __closetransport(self):
try:
self.__sock.close()
except:
pass
self.__connectionid = None
self.__client = None
def __checkconnected(self):
if self.__client is None:
raise OBEXError("must connect() before sending other requests")
def __createresponse(self, resp):
headers = resp[1]
for hid, value in headers.items():
if hid == 0x44:
headers[hid] = _obexcommon._datetimefromstring(value[:])
elif hid == 0xC4:
headers[hid] = datetime.datetime.fromtimestamp(value)
elif type(value) == buffer:
headers[hid] = value[:]
return _obexcommon.OBEXResponse(resp[0], headers)
def __convertheaders(self, headers):
result = {}
for header, value in headers.items():
if isinstance(header, types.StringTypes):
hid = \
_obexcommon._HEADER_STRINGS_TO_IDS.get(header.lower())
else:
hid = header
if hid is None:
raise ValueError("unknown header '%s'" % header)
if isinstance(value, datetime.datetime):
value = value.strftime("%Y%m%dT%H%M%S")
self.__checkheadervalue(header, hid, value)
result[hid] = value
if self.__connectionid is not None:
result[_lightblueobex.CONNECTION_ID] = self.__connectionid
return result
def __checkheadervalue(self, header, hid, value):
mask = hid & _HEADER_MASK
if mask == _HEADER_UNICODE:
if not isinstance(value, types.StringTypes):
raise TypeError("value for '%s' must be string, was %s" %
(str(header), type(value)))
elif mask == _HEADER_BYTE_SEQ:
try:
buffer(value)
except:
raise TypeError("value for '%s' must be string, array or other buffer type, was %s" % (str(header), type(value)))
elif mask == _HEADER_1BYTE:
if not isinstance(value, int):
raise TypeError("value for '%s' must be int, was %s" %
(str(header), type(value)))
elif mask == _HEADER_4BYTE:
if not isinstance(value, int) and not isinstance(value, long):
raise TypeError("value for '%s' must be int, was %s" %
(str(header), type(value)))
# set method docstrings
definedmethods = locals() # i.e. defined methods in OBEXClient
for name, doc in _obexcommon._obexclientdocs.items():
try:
definedmethods[name].__doc__ = doc
except KeyError:
pass
# ---------------------------------------------------------------------
def sendfile(address, channel, source):
if not _lightbluecommon._isbtaddr(address):
raise TypeError("address '%s' is not a valid bluetooth address" \
% address)
if not isinstance(channel, int):
raise TypeError("channel must be int, was %s" % type(channel))
if not isinstance(source, types.StringTypes) and \
not hasattr(source, "read"):
raise TypeError("source must be string or file-like object with read() method")
if isinstance(source, types.StringTypes):
headers = {"name": source}
fileobj = file(source, "rb")
closefileobj = True
else:
if hasattr(source, "name"):
headers = {"name": source.name}
fileobj = source
closefileobj = False
client = OBEXClient(address, channel)
client.connect()
try:
resp = client.put(headers, fileobj)
finally:
if closefileobj:
fileobj.close()
try:
client.disconnect()
except:
pass # always ignore disconnection errors
if resp.code != _obexcommon.OK:
raise OBEXError("server denied the Put request")
# ---------------------------------------------------------------------
# This OBEXObjectPushServer class provides an Object Push server for the
# recvfile() function, and accepts Connect, Disconnect and Put requests.
# It uses the OBEXServer class in the _lightblueobex extension, which provides
# a generic OBEX server class that can handle any type of requests. You can
# use that class to implement other types of OBEX servers, e.g. for the File
# Transfer Profile.
class OBEXObjectPushServer(object):
def __init__(self, fileno, fileobject):
if not hasattr(fileobject, "write"):
raise TypeError("fileobject must be file-like object with write() method")
self.__fileobject = fileobject
self.__server = _lightblueobex.OBEXServer(fileno, self.error,
self.newrequest, self.requestdone)
def run(self):
timeout = 60
self.__gotfile = False
self.__disconnected = False
self.__error = None
while True:
result = self.__server.process(timeout)
if result < 0:
#print "-> error during process()"
if self.__error is None:
self.__error = (OBEXError, "error while running server")
break
if result == 0:
#print "-> process() timed out"
break
if self.__gotfile:
#print "-> got file!"
break
if self.__error is not None and not self.__busy:
#print "-> server error detected..."
break
if self.__gotfile:
# wait briefly for disconnect request
while not self.__disconnected:
if self.__server.process(3) <= 0:
break
if not self.__gotfile:
if self.__error is not None:
exc, msg = self.__error
if exc == IOError:
exc = OBEXError
raise exc(msg)
raise OBEXError("client did not send a file")
def newrequest(self, opcode, reqheaders, nonheaderdata, hasbody):
#print "-> newrequest", opcode, reqheaders, nonheaderdata, hasbody
#print "-> incoming file name:", reqheaders.get(0x01)
self.__busy = True
if opcode == _lightblueobex.PUT:
return (_lightblueobex.SUCCESS, {}, self.__fileobject)
elif opcode in (_lightblueobex.CONNECT, _lightblueobex.DISCONNECT):
return (_lightblueobex.SUCCESS, {}, None)
else:
return (_lightblueobex.NOT_IMPLEMENTED, {}, None)
def requestdone(self, opcode):
#print "-> requestdone", opcode
if opcode == _lightblueobex.DISCONNECT:
self.__disconnected = True
elif opcode == _lightblueobex.PUT:
self.__gotfile = True
self.__busy = False
def error(self, exc, msg):
#print "-> error:", exc, msg
if self.__error is not None:
#print "-> (keeping previous error)"
return
self.__error = (exc, msg)
# ---------------------------------------------------------------------
def recvfile(sock, dest):
if sock is None:
raise TypeError("Given socket is None")
if not isinstance(dest, (types.StringTypes, types.FileType)):
raise TypeError("dest must be string or file-like object with write() method")
if isinstance(dest, types.StringTypes):
fileobj = open(dest, "wb")
closefileobj = True
else:
fileobj = dest
closefileobj = False
try:
conn, addr = sock.accept()
# print "A client connected:", addr
server = OBEXObjectPushServer(conn.fileno(), fileobj)
server.run()
conn.close()
finally:
if closefileobj:
fileobj.close()
| 12,651 | _obex | py | en | python | code | {"qsc_code_num_words": 1321, "qsc_code_num_chars": 12651.0, "qsc_code_mean_word_length": 5.41029523, "qsc_code_frac_words_unique": 0.22104466, "qsc_code_frac_chars_top_2grams": 0.01049391, "qsc_code_frac_chars_top_3grams": 0.01679026, "qsc_code_frac_chars_top_4grams": 0.02014831, "qsc_code_frac_chars_dupe_5grams": 0.26612565, "qsc_code_frac_chars_dupe_6grams": 0.21169722, "qsc_code_frac_chars_dupe_7grams": 0.16818245, "qsc_code_frac_chars_dupe_8grams": 0.15335106, "qsc_code_frac_chars_dupe_9grams": 0.13460193, "qsc_code_frac_chars_dupe_10grams": 0.11319435, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00504761, "qsc_code_frac_chars_whitespace": 0.31096356, "qsc_code_size_file_byte": 12651.0, "qsc_code_num_lines": 369.0, "qsc_code_num_chars_line_max": 130.0, "qsc_code_num_chars_line_mean": 34.28455285, "qsc_code_frac_chars_alphabet": 0.81484456, "qsc_code_frac_chars_comments": 0.14852581, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.35687732, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.07437785, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00260975, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 0.0, "qsc_codepython_frac_lines_func_ratio": null, "qsc_codepython_cate_var_zero": null, "qsc_codepython_frac_lines_pass": 0.01115242, "qsc_codepython_frac_lines_import": 0.02973978, "qsc_codepython_frac_lines_simplefunc": null, "qsc_codepython_score_lines_no_logic": null, "qsc_codepython_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 1, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/linux/_lightblue.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
import socket as _socket
try:
import bluetooth # pybluez module
try:
import _bluetooth # pybluez internal implementation module
except:
import bluetooth._bluetooth as _bluetooth
except ImportError, e:
raise ImportError("LightBlue requires PyBluez to be installed, " + \
"cannot find PyBluez 'bluetooth' module: " + str(e))
import _lightbluecommon
import _lightblueutil
# public attributes
__all__ = ("finddevices", "findservices", "finddevicename",
"gethostaddr", "gethostclass",
"socket",
"advertise", "stopadvertise",
"selectdevice", "selectservice")
# device name cache
_devicenames = {}
# map lightblue protocol values to pybluez ones
_PROTOCOLS = { _lightbluecommon.RFCOMM: bluetooth.RFCOMM,
_lightbluecommon.L2CAP: bluetooth.L2CAP }
def finddevices(getnames=True, length=10):
return _SyncDeviceInquiry().run(getnames, length)
def findservices(addr=None, name=None, servicetype=None):
# This always passes a uuid, to force PyBluez to use BlueZ 'search' instead
# of 'browse', otherwise some services won't get found. If you use BlueZ's
# <sdptool search> or <sdptool records> sometimes you'll get services that
# aren't returned through <sdptool browse> -- I think 'browse' only returns
# services with recognised protocols or profiles or something.
if servicetype is None:
uuid = "0100" # L2CAP -- i.e. pretty much all services
elif servicetype == _lightbluecommon.RFCOMM:
uuid = "0003"
elif servicetype == _lightbluecommon.OBEX:
uuid = "0008"
else:
raise ValueError("servicetype must be RFCOMM, OBEX or None, was %s" % \
servicetype)
try:
services = bluetooth.find_service(name=name, uuid=uuid, address=addr)
except bluetooth.BluetoothError, e:
raise _lightbluecommon.BluetoothError(str(e))
if servicetype == _lightbluecommon.RFCOMM:
# OBEX services will be included with RFCOMM services (since OBEX is
# built on top of RFCOMM), so filter out the OBEX services
return [_getservicetuple(s) for s in services if not _isobexservice(s)]
else:
return [_getservicetuple(s) for s in services]
def finddevicename(address, usecache=True):
if not _lightbluecommon._isbtaddr(address):
raise ValueError("%s is not a valid bluetooth address" % str(address))
if address == gethostaddr():
return _gethostname()
if usecache:
name = _devicenames.get(address)
if name is not None:
return name
name = bluetooth.lookup_name(address)
if name is None:
raise _lightbluecommon.BluetoothError(
"Could not find device name for %s" % address)
_devicenames[address] = name
return name
### local device ###
def gethostaddr():
sock = _gethcisock()
try:
try:
addr = _lightblueutil.hci_read_bd_addr(sock.fileno(), 1000)
except IOError, e:
raise _lightbluecommon.BluetoothError(str(e))
finally:
sock.close()
return addr
def gethostclass():
sock = _gethcisock()
try:
try:
cod = _lightblueutil.hci_read_class_of_dev(sock.fileno(), 1000)
except IOError, e:
raise _lightbluecommon.BluetoothError(str(e))
finally:
sock.close()
return _lightbluecommon._joinclass(cod)
def _gethostname():
sock = _gethcisock()
try:
try:
name = _lightblueutil.hci_read_local_name(sock.fileno(), 1000)
except IOError, e:
raise _lightbluecommon.BluetoothError(str(e))
finally:
sock.close()
return name
### socket ###
class _SocketWrapper(object):
def __init__(self, sock):
self.__dict__["_sock"] = sock
self.__dict__["_advertised"] = False
self.__dict__["_listening"] = False
# must implement accept() to return _SocketWrapper objects
def accept(self):
try:
# access _sock._sock (i.e. pybluez socket's internal sock)
# this is so we can raise timeout errors with a different exception
conn, addr = self._sock._sock.accept()
except _bluetooth.timeout, te:
raise _socket.timeout(str(te))
except _bluetooth.error, e:
raise _socket.error(str(e))
# return new _SocketWrapper that wraps a new BluetoothSocket
newsock = bluetooth.BluetoothSocket(_sock=conn)
return (_SocketWrapper(newsock), addr)
accept.__doc__ = _lightbluecommon._socketdocs["accept"]
def listen(self, backlog):
if not self._listening:
self._sock.listen(backlog)
self._listening = True
# must implement dup() to return _SocketWrapper objects
def dup(self):
return _SocketWrapper(self._sock.dup())
dup.__doc__ = _lightbluecommon._socketdocs["dup"]
def getsockname(self):
sockname = self._sock.getsockname()
if sockname[1] != 0:
return (gethostaddr(), sockname[1])
return sockname # not connected, should be ("00:00:00:00:00:00", 0)
getsockname.__doc__ = _lightbluecommon._socketdocs["getsockname"]
# redefine methods that can raise timeout errors, to access _sock._sock
# in order to raise timeout errors with a different exception
# (otherwise they are raised as generic BluetoothException)
_methoddef = """def %s(self, *args, **kwargs):
try:
return self._sock._sock.%s(*args, **kwargs)
except _bluetooth.timeout, te:
raise _socket.timeout(str(te))
except _bluetooth.error, e:
raise _socket.error(str(e))
%s.__doc__ = _lightbluecommon._socketdocs['%s']\n"""
for _m in ("connect", "send", "recv"):
exec _methoddef % (_m, _m, _m, _m)
del _m, _methoddef
# wrap all other socket methods, to set LightBlue-specific docstrings
_othermethods = [_m for _m in _lightbluecommon._socketdocs.keys() \
if _m not in locals()] # methods other than those already defined
_methoddef = """def %s(self, *args, **kwargs):
try:
return self._sock.%s(*args, **kwargs)
except _bluetooth.error, e:
raise _socket.error(str(e))
%s.__doc__ = _lightbluecommon._socketdocs['%s']\n"""
for _m in _othermethods:
exec _methoddef % (_m, _m, _m, _m)
del _m, _methoddef
def socket(proto=_lightbluecommon.RFCOMM):
# return a wrapped BluetoothSocket
sock = bluetooth.BluetoothSocket(_PROTOCOLS[proto])
return _SocketWrapper(sock)
### advertising services ###
def advertise(servicename, sock, serviceclass):
try:
if serviceclass == _lightbluecommon.RFCOMM:
bluetooth.advertise_service(sock._sock,
servicename,
service_classes=[bluetooth.SERIAL_PORT_CLASS],
profiles=[bluetooth.SERIAL_PORT_PROFILE])
elif serviceclass == _lightbluecommon.OBEX:
# for pybluez, socket do need to be listening in order to
# advertise a service, so we'll call listen() here. This should be
# safe since user shouldn't have called listen() already, because
# obex.recvfile() docs state that an obex server socket should
# *not* be listening before recvfile() is called (due to Series60's
# particular implementation)
if not sock._listening:
sock.listen(1)
# advertise Object Push Profile not File Transfer Profile because
# obex.recvfile() implementations run OBEX servers which only
# advertise Object Push operations
bluetooth.advertise_service(sock._sock,
servicename,
service_classes=[bluetooth.OBEX_OBJPUSH_CLASS],
profiles=[bluetooth.OBEX_OBJPUSH_PROFILE],
protocols=["0008"]) # OBEX protocol
else:
raise ValueError("Unknown serviceclass, " + \
"should be either RFCOMM or OBEX constants")
# set flag
sock._advertised = True
except bluetooth.BluetoothError, e:
raise _lightbluecommon.BluetoothError(str(e))
def stopadvertise(sock):
if not sock._advertised:
raise _lightbluecommon.BluetoothError("no service advertised")
try:
bluetooth.stop_advertising(sock._sock)
except bluetooth.BluetoothError, e:
raise _lightbluecommon.BluetoothError(str(e))
sock._advertised = False
### GUI ###
def selectdevice():
import _discoveryui
return _discoveryui.selectdevice()
def selectservice():
import _discoveryui
return _discoveryui.selectservice()
### classes ###
class _SyncDeviceInquiry(object):
def __init__(self):
super(_SyncDeviceInquiry, self).__init__()
self._inquiry = None
def run(self, getnames=True, length=10):
self._founddevices = []
self._inquiry = _MyDiscoverer(self._founddevice, self._inquirycomplete)
try:
self._inquiry.find_devices(lookup_names=getnames, duration=length)
# block until inquiry finishes
self._inquiry.process_inquiry()
except bluetooth.BluetoothError, e:
try:
self._inquiry.cancel_inquiry()
finally:
raise _lightbluecommon.BluetoothError(e)
return self._founddevices
def _founddevice(self, address, deviceclass, name):
self._founddevices.append(_getdevicetuple(address, deviceclass, name))
def _inquirycomplete(self):
pass
# subclass of PyBluez DeviceDiscoverer class for customised async discovery
class _MyDiscoverer(bluetooth.DeviceDiscoverer):
# _MyDiscoverer inherits 2 major methods for discovery:
# - find_devices(lookup_names=True, duration=8, flush_cache=True)
# - cancel_inquiry()
def __init__(self, founddevicecallback, completedcallback):
bluetooth.DeviceDiscoverer.__init__(self) # old-style superclass, no super()
self.founddevicecallback = founddevicecallback
self.completedcallback = completedcallback
def device_discovered(self, address, deviceclass, name):
self.founddevicecallback(address, deviceclass, name)
def inquiry_complete(self):
self.completedcallback()
### utility methods ###
def _getdevicetuple(address, deviceclass, name):
# Return as (addr, name, cod) tuple.
return (address, name, deviceclass)
def _getservicetuple(service):
"""
Returns a (addr, port, name) tuple from a PyBluez service dictionary, which
should have at least:
- "name": service name
- "port": service channel/PSM etc.
- "host": address of host device
"""
return (service["host"], service["port"], service["name"])
# assume a service is an OBEX-type service if it advertises Object Push, File
# Transfer or Synchronization classes, since their respective profiles are
# listed as using the OBEX protocol in the bluetooth specs
_obexserviceclasses = (
bluetooth.OBEX_OBJPUSH_CLASS,
bluetooth.OBEX_FILETRANS_CLASS,
bluetooth.IRMC_SYNC_CMD_CLASS
)
def _isobexservice(service):
for sc in service["service-classes"]:
if sc in _obexserviceclasses:
return True
return False
# Gets HCI socket thru PyBluez. Remember to close the returned socket.
def _gethcisock(devid=-1):
try:
sock = _bluetooth.hci_open_dev(devid)
except Exception, e:
raise _lightbluecommon.BluetoothError(
"Cannot access local device: " + str(e))
return sock
| 12,484 | _lightblue | py | en | python | code | {"qsc_code_num_words": 1377, "qsc_code_num_chars": 12484.0, "qsc_code_mean_word_length": 5.78358751, "qsc_code_frac_words_unique": 0.27015251, "qsc_code_frac_chars_top_2grams": 0.00828729, "qsc_code_frac_chars_top_3grams": 0.04269211, "qsc_code_frac_chars_top_4grams": 0.03076344, "qsc_code_frac_chars_dupe_5grams": 0.18043697, "qsc_code_frac_chars_dupe_6grams": 0.16034656, "qsc_code_frac_chars_dupe_7grams": 0.15005023, "qsc_code_frac_chars_dupe_8grams": 0.13071321, "qsc_code_frac_chars_dupe_9grams": 0.13071321, "qsc_code_frac_chars_dupe_10grams": 0.08073832, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00666308, "qsc_code_frac_chars_whitespace": 0.25464595, "qsc_code_size_file_byte": 12484.0, "qsc_code_num_lines": 370.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 33.74054054, "qsc_code_frac_chars_alphabet": 0.84922085, "qsc_code_frac_chars_comments": 0.25512656, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.32286996, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.11945126, "qsc_code_frac_chars_long_word_length": 0.01829132, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 0.0, "qsc_codepython_frac_lines_func_ratio": null, "qsc_codepython_cate_var_zero": null, "qsc_codepython_frac_lines_pass": 0.0044843, "qsc_codepython_frac_lines_import": 0.04484305, "qsc_codepython_frac_lines_simplefunc": null, "qsc_codepython_score_lines_no_logic": null, "qsc_codepython_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 1, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/__init__.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"LightBlue - a simple bluetooth library."
# Docstrings for attributes in this module.
_docstrings = {
"finddevices":
"""
Performs a device discovery and returns the found devices as a list of
(address, name, class-of-device) tuples. Raises BluetoothError if an error
occurs.
Arguments:
- getnames=True: True if device names should be retrieved during
discovery. If false, None will be returned instead of the device
name.
- length=10: the number of seconds to spend discovering devices
(this argument has no effect on Python for Series 60)
Do not invoke a new discovery before a previous discovery has finished.
Also, to minimise interference with other wireless and bluetooth traffic,
and to conserve battery power on the local device, discoveries should not
be invoked too frequently (an interval of at least 20 seconds is
recommended).
""",
"findservices":
"""
Performs a service discovery and returns the found services as a list of
(device-address, service-port, service-name) tuples. Raises BluetoothError
if an error occurs.
Arguments:
- addr=None: a device address, to search only for services on a
specific device
- name=None: a service name string, to search only for a service with a
specific name
- servicetype=None: can be RFCOMM or OBEX to search only for RFCOMM or
OBEX-type services. (OBEX services are not returned from an RFCOMM
search)
If more than one criteria is specified, this returns services that match
all criteria.
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.
""",
"finddevicename":
"""
Returns the name of the device with the given bluetooth address.
finddevicename(gethostaddr()) returns the local device name.
Arguments:
- address: the address of the device to look up
- usecache=True: if True, the device name will be fetched from a local
cache if possible. If False, or if the device name is not in the
cache, the remote device will be contacted to request its name.
Raise BluetoothError if the name cannot be retrieved.
""",
"gethostaddr":
"""
Returns the address of the local bluetooth device.
Raise BluetoothError if the local device is not available.
""",
"gethostclass":
"""
Returns the class of device of the local bluetooth device.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Raise BluetoothError if the local device is not available.
""",
"socket":
"""
socket(proto=RFCOMM) -> socket object
Returns a new socket object.
Arguments:
- proto=RFCOMM: the type of socket to be created - either L2CAP or
RFCOMM.
Note that L2CAP sockets are not available on Python For Series 60, and
only L2CAP client sockets are supported on Mac OS X and Linux (i.e. you can
connect() the socket but not bind(), accept(), etc.).
""",
"advertise":
"""
Starts advertising a service with the given name, using the given server
socket. Raises BluetoothError if the service cannot be advertised.
Arguments:
- name: name of the service to be advertised
- sock: the socket object that will serve this service. The socket must
be already bound to a channel. If a RFCOMM service is being
advertised, the socket should also be listening.
- servicetype: the type of service to advertise - either RFCOMM or
OBEX. (L2CAP services are not currently supported.)
(If the servicetype is RFCOMM, the service will be advertised with the
Serial Port Profile; if the servicetype is OBEX, the service will be
advertised with the OBEX Object Push Profile.)
""",
"stopadvertise":
"""
Stops advertising the service on the given socket. Raises BluetoothError if
no service is advertised on the socket.
This will error if the given socket is already closed.
""",
"selectdevice":
"""
Displays a GUI which allows the end user to select a device from a list of
discovered devices.
Returns the selected device as an (address, name, class-of-device) tuple.
Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
""",
"selectservice":
"""
Displays a GUI which allows the end user to select a service from a list of
discovered devices and their services.
Returns the selected service as a (device-address, service-port, service-
name) tuple. Returns None if the selection was cancelled.
(On Python For Series 60, the device selection will fail if there are any
open bluetooth connections.)
Currently the Python for Series 60 implementation will only find RFCOMM and
OBEX services.
"""
}
# import implementation modules
from _lightblue import *
from _lightbluecommon import *
import obex # plus submodule
# set docstrings
import _lightblue
localattrs = locals()
for attr in _lightblue.__all__:
try:
localattrs[attr].__doc__ = _docstrings[attr]
except KeyError:
pass
del attr, localattrs
| 6,362 | __init__ | py | en | python | code | {"qsc_code_num_words": 877, "qsc_code_num_chars": 6362.0, "qsc_code_mean_word_length": 4.99657925, "qsc_code_frac_words_unique": 0.32041049, "qsc_code_frac_chars_top_2grams": 0.01141031, "qsc_code_frac_chars_top_3grams": 0.02053857, "qsc_code_frac_chars_top_4grams": 0.02327704, "qsc_code_frac_chars_dupe_5grams": 0.26289366, "qsc_code_frac_chars_dupe_6grams": 0.21497033, "qsc_code_frac_chars_dupe_7grams": 0.17343679, "qsc_code_frac_chars_dupe_8grams": 0.15837517, "qsc_code_frac_chars_dupe_9grams": 0.13555454, "qsc_code_frac_chars_dupe_10grams": 0.13555454, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00527649, "qsc_code_frac_chars_whitespace": 0.25526564, "qsc_code_size_file_byte": 6362.0, "qsc_code_num_lines": 172.0, "qsc_code_num_chars_line_max": 81.0, "qsc_code_num_chars_line_mean": 36.98837209, "qsc_code_frac_chars_alphabet": 0.91958632, "qsc_code_frac_chars_comments": 0.12951902, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.27191413, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.03030303, "qsc_codepython_frac_lines_import": 0.12121212, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.12121212, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/_lightbluecommon.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
# Defines attributes with common implementations across the different
# platforms.
# public attributes
__all__ = ("L2CAP", "RFCOMM", "OBEX", "BluetoothError", "splitclass")
# Protocol/service class types, used for sockets and advertising services
L2CAP, RFCOMM, OBEX = (10, 11, 12)
class BluetoothError(IOError):
"""
Generic exception raised for Bluetooth errors. This is not raised for
socket-related errors; socket objects raise the socket.error and
socket.timeout exceptions from the standard library socket module.
Note that error codes are currently platform-independent. In particular,
the Mac OS X implementation returns IOReturn error values from the IOKit
framework, and OBEXError codes from <IOBluetooth/OBEX.h> for OBEX operations.
"""
pass
def splitclass(classofdevice):
"""
Splits the given class of device to return a 3-item tuple with the
major service class, major device class and minor device class values.
These values indicate the device's major services and the type of the
device (e.g. mobile phone, laptop, etc.). If you google for
"assigned numbers bluetooth baseband" you might find some documents
that discuss how to extract this information from the class of device.
Example:
>>> splitclass(1057036)
(129, 1, 3)
>>>
"""
if not isinstance(classofdevice, int):
try:
classofdevice = int(classofdevice)
except (TypeError, ValueError):
raise TypeError("Given device class '%s' cannot be split" % \
str(classofdevice))
data = classofdevice >> 2 # skip over the 2 "format" bits
service = data >> 11
major = (data >> 6) & 0x1F
minor = data & 0x3F
return (service, major, minor)
_validbtaddr = None
def _isbtaddr(address):
"""
Returns whether the given address is a valid bluetooth address.
For example, "00:0e:6d:7b:a2:0a" is a valid address.
Returns False if the argument is None or is not a string.
"""
# Define validity regex. Accept either ":" or "-" as separators.
global _validbtaddr
if _validbtaddr is None:
import re
_validbtaddr = re.compile("((\d|[a-f]){2}(:|-)){5}(\d|[a-f]){2}",
re.IGNORECASE)
import types
if not isinstance(address, types.StringTypes):
return False
return _validbtaddr.match(address) is not None
# --------- other attributes ---------
def _joinclass(codtuple):
"""
The opposite of splitclass(). Joins a (service, major, minor) class-of-
device tuple into a whole class of device value.
"""
if not isinstance(codtuple, tuple):
raise TypeError("argument must be tuple, was %s" % type(codtuple))
if len(codtuple) != 3:
raise ValueError("tuple must have 3 items, has %d" % len(codtuple))
serviceclass = codtuple[0] << 2 << 11
majorclass = codtuple[1] << 2 << 6
minorclass = codtuple[2] << 2
return (serviceclass | majorclass | minorclass)
# Docstrings for socket objects.
# Based on std lib socket docs.
_socketdocs = {
"accept":
"""
accept() -> (socket object, address info)
Wait for an incoming connection. Return a new socket representing the
connection, and the address of the client. For RFCOMM sockets, the address
info is a pair (hostaddr, channel).
The socket must be bound and listening before calling this method.
""",
"bind":
"""
bind(address)
Bind the socket to a local address. For RFCOMM sockets, the address is a
pair (host, channel); the host must refer to the local host.
A port value of 0 binds the socket to a dynamically assigned port.
(Note that on Mac OS X, the port value must always be 0.)
The socket must not already be bound.
""",
"close":
"""
close()
Close the socket. It cannot be used after this call.
""",
"connect":
"""
connect(address)
Connect the socket to a remote address. The address should be a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
The socket must not be already connected.
""",
"connect_ex":
"""
connect_ex(address) -> errno
This is like connect(address), but returns an error code instead of raising
an exception when an error occurs.
""",
"dup":
"""
dup() -> socket object
Returns a new socket object connected to the same system resource.
""",
"fileno":
"""
fileno() -> integer
Return the integer file descriptor of the socket.
Raises NotImplementedError on Mac OS X and Python For Series 60.
""",
"getpeername":
"""
getpeername() -> address info
Return the address of the remote endpoint. The address info is a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
If the socket has not been connected, socket.error will be raised.
""",
"getsockname":
"""
getsockname() -> address info
Return the address of the local endpoint. The address info is a
(host, channel) pair for RFCOMM sockets, and a (host, PSM) pair for L2CAP
sockets.
If the socket has not been connected nor bound, this returns the tuple
("00:00:00:00:00:00", 0).
""",
"getsockopt":
"""
getsockopt(level, option[, bufsize]) -> value
Get a socket option. See the Unix manual for level and option.
If a nonzero buffersize argument is given, the return value is a
string of that length; otherwise it is an integer.
Currently support for socket options are platform independent -- i.e.
depends on the underlying Series 60 or BlueZ socket options support.
The Mac OS X implementation currently does not support any options at
all and automatically raises socket.error.
""",
"gettimeout":
"""
gettimeout() -> timeout
Returns the timeout in floating seconds associated with socket
operations. A timeout of None indicates that timeouts on socket
operations are disabled.
Currently not supported on Python For Series 60 implementation, which
will always return None.
""",
"listen":
"""
listen(backlog)
Enable a server to accept connections. The backlog argument must be at
least 1; it specifies the number of unaccepted connection that the system
will allow before refusing new connections.
The socket must not be already listening.
Currently not implemented on Mac OS X.
""",
"makefile":
"""
makefile([mode[, bufsize]]) -> file object
Returns a regular file object corresponding to the socket. The mode
and bufsize arguments are as for the built-in open() function.
""",
"recv":
"""
recv(bufsize[, flags]) -> data
Receive up to bufsize bytes from the socket. For the optional flags
argument, see the Unix manual. When no data is available, block until
at least one byte is available or until the remote end is closed. When
the remote end is closed and all data is read, return the empty string.
Currently the flags argument has no effect on Mac OS X.
""",
"recvfrom":
"""
recvfrom(bufsize[, flags]) -> (data, address info)
Like recv(buffersize, flags) but also return the sender's address info.
""",
"send":
"""
send(data[, flags]) -> count
Send a data string to the socket. For the optional flags
argument, see the Unix manual. Return the number of bytes
sent.
The socket must be connected to a remote socket.
Currently the flags argument has no effect on Mac OS X.
""",
"sendall":
"""
sendall(data[, flags])
Send a data string to the socket. For the optional flags
argument, see the Unix manual. This calls send() repeatedly
until all data is sent. If an error occurs, it's impossible
to tell how much data has been sent.
""",
"sendto":
"""
sendto(data[, flags], address) -> count
Like send(data, flags) but allows specifying the destination address.
For RFCOMM sockets, the address is a pair (hostaddr, channel).
""",
"setblocking":
"""
setblocking(flag)
Set the socket to blocking (flag is true) or non-blocking (false).
setblocking(True) is equivalent to settimeout(None);
setblocking(False) is equivalent to settimeout(0.0).
Initially a socket is in blocking mode. In non-blocking mode, if a
socket operation cannot be performed immediately, socket.error is raised.
The underlying implementation on Python for Series 60 only supports
non-blocking mode for send() and recv(), and ignores it for connect() and
accept().
""",
"setsockopt":
"""
setsockopt(level, option, value)
Set a socket option. See the Unix manual for level and option.
The value argument can either be an integer or a string.
Currently support for socket options are platform independent -- i.e.
depends on the underlying Series 60 or BlueZ socket options support.
The Mac OS X implementation currently does not support any options at
all and automatically raise socket.error.
""",
"settimeout":
"""
settimeout(timeout)
Set a timeout on socket operations. 'timeout' can be a float,
giving in seconds, or None. Setting a timeout of None disables
the timeout feature and is equivalent to setblocking(1).
Setting a timeout of zero is the same as setblocking(0).
If a timeout is set, the connect, accept, send and receive operations will
raise socket.timeout if a timeout occurs.
Raises NotImplementedError on Python For Series 60.
""",
"shutdown":
"""
shutdown(how)
Shut down the reading side of the socket (flag == socket.SHUT_RD), the
writing side of the socket (flag == socket.SHUT_WR), or both ends
(flag == socket.SHUT_RDWR).
"""
}
| 10,831 | _lightbluecommon | py | en | python | code | {"qsc_code_num_words": 1463, "qsc_code_num_chars": 10831.0, "qsc_code_mean_word_length": 4.88311688, "qsc_code_frac_words_unique": 0.2836637, "qsc_code_frac_chars_top_2grams": 0.02519597, "qsc_code_frac_chars_top_3grams": 0.00671892, "qsc_code_frac_chars_top_4grams": 0.0055991, "qsc_code_frac_chars_dupe_5grams": 0.22074468, "qsc_code_frac_chars_dupe_6grams": 0.18924972, "qsc_code_frac_chars_dupe_7grams": 0.17441209, "qsc_code_frac_chars_dupe_8grams": 0.15733483, "qsc_code_frac_chars_dupe_9grams": 0.15733483, "qsc_code_frac_chars_dupe_10grams": 0.14613662, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01130716, "qsc_code_frac_chars_whitespace": 0.25694765, "qsc_code_size_file_byte": 10831.0, "qsc_code_num_lines": 331.0, "qsc_code_num_chars_line_max": 82.0, "qsc_code_num_chars_line_mean": 32.72205438, "qsc_code_frac_chars_alphabet": 0.8763668, "qsc_code_frac_chars_comments": 0.20801403, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.1814301, "qsc_code_frac_chars_long_word_length": 0.01921025, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00426894, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.03703704, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.01234568, "qsc_codepython_frac_lines_import": 0.02469136, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.12345679, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/_LightAquaBlue.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"""
Provides a python interface to the LightAquaBlue Framework classes, through
PyObjC.
See http://pyobjc.sourceforge.net for details on how to access Objective-C
classes through PyObjC.
"""
import objc
import os.path
_FRAMEWORK_PATH = u'/Library/Frameworks/LightAquaBlue.framework'
if not os.path.isdir(_FRAMEWORK_PATH):
raise ImportError("Cannot load LightAquaBlue framework, not found at" + \
_FRAMEWORK_PATH)
try:
# mac os 10.5 loads frameworks using bridgesupport metadata
__bundle__ = objc.initFrameworkWrapper("LightAquaBlue",
frameworkIdentifier="com.blammit.LightAquaBlue",
frameworkPath=objc.pathForFramework(_FRAMEWORK_PATH),
globals=globals())
except AttributeError:
# earlier versions use loadBundle() and setSignatureForSelector()
objc.loadBundle("LightAquaBlue", globals(),
bundle_path=objc.pathForFramework(_FRAMEWORK_PATH))
# return int, take (object, object, object, output unsigned char, output int)
# i.e. in python: return (int, char, int), take (object, object, object)
objc.setSignatureForSelector("BBServiceAdvertiser",
"addRFCOMMServiceDictionary:withName:UUID:channelID:serviceRecordHandle:",
"i@0:@@@o^Co^I")
# set to take (6-char array, unsigned char, object)
# this seems to work even though the selector doesn't take a char aray,
# it takes a struct 'BluetoothDeviceAddress' which contains a char array.
objc.setSignatureForSelector("BBBluetoothOBEXClient",
"initWithRemoteDeviceAddress:channelID:delegate:",
'@@:r^[6C]C@')
del objc
| 2,357 | _LightAquaBlue | py | en | python | code | {"qsc_code_num_words": 295, "qsc_code_num_chars": 2357.0, "qsc_code_mean_word_length": 5.74237288, "qsc_code_frac_words_unique": 0.55932203, "qsc_code_frac_chars_top_2grams": 0.03837072, "qsc_code_frac_chars_top_3grams": 0.02302243, "qsc_code_frac_chars_top_4grams": 0.03364817, "qsc_code_frac_chars_dupe_5grams": 0.07792208, "qsc_code_frac_chars_dupe_6grams": 0.03305785, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0057652, "qsc_code_frac_chars_whitespace": 0.19049639, "qsc_code_size_file_byte": 2357.0, "qsc_code_num_lines": 60.0, "qsc_code_num_chars_line_max": 93.0, "qsc_code_num_chars_line_mean": 39.28333333, "qsc_code_frac_chars_alphabet": 0.88207547, "qsc_code_frac_chars_comments": 0.57148918, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.3312946, "qsc_code_frac_chars_long_word_length": 0.21100917, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.0, "qsc_codepython_frac_lines_import": 0.14285714, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.14285714, "qsc_codepython_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 0, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/obex.py | # Copyright (c) 2009 Bea Lam. All rights reserved.
#
# This file is part of LightBlue.
#
# LightBlue is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LightBlue is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
"""
Provides an OBEX client class and convenience functions for sending and
receiving files over OBEX.
This module also defines constants for response code values (without the final
bit set). For example:
>>> import lightblue
>>> lightblue.obex.OK
32 # the OK/Success response 0x20 (i.e. 0xA0 without the final bit)
>>> lightblue.obex.FORBIDDEN
67 # the Forbidden response 0x43 (i.e. 0xC3 without the final bit)
"""
# Docstrings for attributes in this module.
_docstrings = {
"sendfile":
"""
Sends a file to a remote device.
Raises lightblue.obex.OBEXError if an error occurred during the request, or
if the request was refused by the remote device.
Arguments:
- address: the address of the remote device
- channel: the RFCOMM channel of the remote OBEX service
- source: a filename or file-like object, containing the data to be
sent. If a file object is given, it must be opened for reading.
Note you can achieve the same thing using OBEXClient with something like
this:
>>> import lightblue
>>> client = lightblue.obex.OBEXClient(address, channel)
>>> client.connect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> putresponse = client.put({"name": "MyFile.txt"}, file("MyFile.txt", 'rb'))
>>> client.disconnect()
<OBEXResponse reason='OK' code=0x20 (0xa0) headers={}>
>>> if putresponse.code != lightblue.obex.OK:
... raise lightblue.obex.OBEXError("server denied the Put request")
>>>
""",
"recvfile":
"""
Receives a file through an OBEX service.
Arguments:
- sock: the server socket on which the file is to be received. Note
this socket must *not* be listening. Also, an OBEX service should
have been advertised on this socket.
- dest: a filename or file-like object, to which the received data will
be written. If a filename is given, any existing file will be
overwritten. If a file object is given, it must be opened for writing.
For example, to receive a file and save it as "MyFile.txt":
>>> from lightblue import *
>>> s = socket()
>>> s.bind(("", 0))
>>> advertise("My OBEX Service", s, OBEX)
>>> obex.recvfile(s, "MyFile.txt")
"""
}
# import implementation modules
from _obex import *
from _obexcommon import *
import _obex
import _obexcommon
__all__ = _obex.__all__ + _obexcommon.__all__
# set docstrings
localattrs = locals()
for attr in _obex.__all__:
try:
localattrs[attr].__doc__ = _docstrings[attr]
except KeyError:
pass
del attr, localattrs
| 3,421 | obex | py | en | python | code | {"qsc_code_num_words": 468, "qsc_code_num_chars": 3421.0, "qsc_code_mean_word_length": 4.86752137, "qsc_code_frac_words_unique": 0.41880342, "qsc_code_frac_chars_top_2grams": 0.03424056, "qsc_code_frac_chars_top_3grams": 0.01712028, "qsc_code_frac_chars_top_4grams": 0.02502195, "qsc_code_frac_chars_dupe_5grams": 0.12467076, "qsc_code_frac_chars_dupe_6grams": 0.11325724, "qsc_code_frac_chars_dupe_7grams": 0.0667252, "qsc_code_frac_chars_dupe_8grams": 0.03248464, "qsc_code_frac_chars_dupe_9grams": 0.03248464, "qsc_code_frac_chars_dupe_10grams": 0.03248464, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01152074, "qsc_code_frac_chars_whitespace": 0.23881906, "qsc_code_size_file_byte": 3421.0, "qsc_code_num_lines": 97.0, "qsc_code_num_chars_line_max": 87.0, "qsc_code_num_chars_line_mean": 35.26804124, "qsc_code_frac_chars_alphabet": 0.86328725, "qsc_code_frac_chars_comments": 0.35311312, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.04324324, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codepython_cate_ast": 1.0, "qsc_codepython_frac_lines_func_ratio": 0.0, "qsc_codepython_cate_var_zero": false, "qsc_codepython_frac_lines_pass": 0.05882353, "qsc_codepython_frac_lines_import": 0.23529412, "qsc_codepython_frac_lines_simplefunc": 0.0, "qsc_codepython_score_lines_no_logic": 0.23529412, "qsc_codepython_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codepython_cate_ast": 0, "qsc_codepython_frac_lines_func_ratio": 0, "qsc_codepython_cate_var_zero": 0, "qsc_codepython_frac_lines_pass": 1, "qsc_codepython_frac_lines_import": 0, "qsc_codepython_frac_lines_simplefunc": 0, "qsc_codepython_score_lines_no_logic": 0, "qsc_codepython_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/wands/WandOfLivingEarth.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.wands;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Challenges;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Amok;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.npcs.NPC;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.MagesStaff;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.EarthGuardianSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.ColorMath;
import com.watabou.utils.PathFinder;
import com.watabou.utils.Random;
public class WandOfLivingEarth extends DamageWand {
{
image = ItemSpriteSheet.WAND_LIVING_EARTH;
}
@Override
public int min(int lvl) {
return 4;
}
@Override
public int max(int lvl) {
return 6 + 2*lvl;
}
@Override
protected void onZap(Ballistica bolt) {
Char ch = Actor.findChar(bolt.collisionPos);
int damage = damageRoll();
int armorToAdd = damage;
EarthGuardian guardian = null;
for (Mob m : Dungeon.level.mobs){
if (m instanceof EarthGuardian){
guardian = (EarthGuardian) m;
break;
}
}
RockArmor buff = curUser.buff(RockArmor.class);
if (ch == null){
armorToAdd = 0;
} else {
if (buff == null && guardian == null) {
buff = Buff.affect(curUser, RockArmor.class);
}
if (buff != null) {
buff.addArmor(level(), armorToAdd);
}
}
//shooting at the guardian
if (guardian != null && guardian == ch){
guardian.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level() / 2);
guardian.setInfo(curUser, level(), armorToAdd);
processSoulMark(guardian, chargesPerCast());
//shooting the guardian at a location
} else if ( guardian == null && buff != null && buff.armor >= buff.armorToGuardian()){
//create a new guardian
guardian = new EarthGuardian();
guardian.setInfo(curUser, level(), buff.armor);
//if the collision pos is occupied (likely will be), then spawn the guardian in the
//adjacent cell which is closes to the user of the wand.
if (ch != null){
ch.sprite.centerEmitter().burst(MagicMissile.EarthParticle.BURST, 5 + level()/2);
processSoulMark(ch, chargesPerCast());
ch.damage(damage, this);
int closest = -1;
boolean[] passable = Dungeon.level.passable;
for (int n : PathFinder.NEIGHBOURS9) {
int c = bolt.collisionPos + n;
if (passable[c] && Actor.findChar( c ) == null
&& (closest == -1 || (Dungeon.level.trueDistance(c, curUser.pos) < (Dungeon.level.trueDistance(closest, curUser.pos))))) {
closest = c;
}
}
if (closest == -1){
curUser.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level()/2);
return; //do not spawn guardian or detach buff
} else {
guardian.pos = closest;
GameScene.add(guardian, 1);
Dungeon.level.occupyCell(guardian);
}
if (ch.alignment == Char.Alignment.ENEMY || ch.buff(Amok.class) != null) {
guardian.aggro(ch);
}
} else {
guardian.pos = bolt.collisionPos;
GameScene.add(guardian, 1);
Dungeon.level.occupyCell(guardian);
}
guardian.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level()/2);
buff.detach();
//shooting at a location/enemy with no guardian being shot
} else {
if (ch != null) {
ch.sprite.centerEmitter().burst(MagicMissile.EarthParticle.BURST, 5 + level() / 2);
processSoulMark(ch, chargesPerCast());
ch.damage(damage, this);
if (guardian == null) {
curUser.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level() / 2);
} else {
guardian.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level() / 2);
guardian.setInfo(curUser, level(), armorToAdd);
if (ch.alignment == Char.Alignment.ENEMY || ch.buff(Amok.class) != null) {
guardian.aggro(ch);
}
}
} else {
Dungeon.level.pressCell(bolt.collisionPos);
}
}
}
@Override
protected void fx(Ballistica bolt, Callback callback) {
MagicMissile.boltFromChar(curUser.sprite.parent,
MagicMissile.EARTH,
curUser.sprite,
bolt.collisionPos,
callback);
Sample.INSTANCE.play(Assets.SND_ZAP);
}
@Override
public void onHit(MagesStaff staff, Char attacker, Char defender, int damage) {
EarthGuardian guardian = null;
for (Mob m : Dungeon.level.mobs){
if (m instanceof EarthGuardian){
guardian = (EarthGuardian) m;
break;
}
}
int armor = Math.round(damage*0.25f);
if (guardian != null){
guardian.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level() / 2);
guardian.setInfo(Dungeon.hero, level(), armor);
} else {
attacker.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + level() / 2);
Buff.affect(attacker, RockArmor.class).addArmor(level(), armor);
}
}
@Override
public void staffFx(MagesStaff.StaffParticle particle) {
if (Random.Int(10) == 0){
particle.color(ColorMath.random(0xFFF568, 0x80791A));
} else {
particle.color(ColorMath.random(0x805500, 0x332500));
}
particle.am = 1f;
particle.setLifespan(2f);
particle.setSize( 1f, 2f);
particle.shuffleXY(0.5f);
float dst = Random.Float(11f);
particle.x -= dst;
particle.y += dst;
}
public static class RockArmor extends Buff {
private int wandLevel;
private int armor;
private void addArmor( int wandLevel, int toAdd ){
this.wandLevel = Math.max(this.wandLevel, wandLevel);
armor += toAdd;
armor = Math.min(armor, 2*armorToGuardian());
}
private int armorToGuardian(){
return 8 + wandLevel*4;
}
public int absorb( int damage ) {
int block = damage - damage/2;
if (armor <= block) {
detach();
return damage - armor;
} else {
armor -= block;
BuffIndicator.refreshHero();
return damage - block;
}
}
@Override
public int icon() {
return BuffIndicator.ARMOR;
}
@Override
public String toString() {
return Messages.get(this, "name");
}
@Override
public String desc() {
return Messages.get( this, "desc", armor, armorToGuardian());
}
private static final String WAND_LEVEL = "wand_level";
private static final String ARMOR = "armor";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put(WAND_LEVEL, wandLevel);
bundle.put(ARMOR, armor);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
wandLevel = bundle.getInt(WAND_LEVEL);
armor = bundle.getInt(ARMOR);
}
}
public static class EarthGuardian extends NPC {
{
spriteClass = EarthGuardianSprite.class;
alignment = Alignment.ALLY;
state = HUNTING;
intelligentAlly = true;
WANDERING = new Wandering();
//before other mobs
actPriority = MOB_PRIO + 1;
HP = HT = 0;
}
private int wandLevel = -1;
private void setInfo(Hero hero, int wandLevel, int healthToAdd){
if (wandLevel > this.wandLevel) {
this.wandLevel = wandLevel;
HT = 16 + 8 * wandLevel;
}
HP = Math.min(HT, HP + healthToAdd);
//half of hero's evasion
defenseSkill = (hero.lvl + 4)/2;
}
@Override
public int attackSkill(Char target) {
//same as the hero
return 2*defenseSkill + 5;
}
@Override
public int attackProc(Char enemy, int damage) {
if (enemy instanceof Mob) ((Mob)enemy).aggro(this);
return super.attackProc(enemy, damage);
}
@Override
public int damageRoll() {
return Random.NormalIntRange(2, 4 + Dungeon.depth/2);
}
@Override
public int drRoll() {
if (Dungeon.isChallenged(Challenges.NO_ARMOR)){
return Random.NormalIntRange(wandLevel, 2 + wandLevel);
} else {
return Random.NormalIntRange(wandLevel, 3 + 3 * wandLevel);
}
}
@Override
public String description() {
if (Dungeon.isChallenged(Challenges.NO_ARMOR)){
return Messages.get(this, "desc", wandLevel, 2 + wandLevel);
} else {
return Messages.get(this, "desc", wandLevel, 3 + 3*wandLevel);
}
}
private static final String DEFENSE = "defense";
private static final String WAND_LEVEL = "wand_level";
@Override
public void storeInBundle(Bundle bundle) {
super.storeInBundle(bundle);
bundle.put(DEFENSE, defenseSkill);
bundle.put(WAND_LEVEL, wandLevel);
}
@Override
public void restoreFromBundle(Bundle bundle) {
super.restoreFromBundle(bundle);
defenseSkill = bundle.getInt(DEFENSE);
wandLevel = bundle.getInt(WAND_LEVEL);
}
private class Wandering extends Mob.Wandering{
@Override
public boolean act(boolean enemyInFOV, boolean justAlerted) {
if (!enemyInFOV){
Buff.affect(Dungeon.hero, RockArmor.class).addArmor(wandLevel, HP);
Dungeon.hero.sprite.centerEmitter().burst(MagicMissile.EarthParticle.ATTRACT, 8 + wandLevel/2);
destroy();
sprite.die();
return true;
} else {
return super.act(enemyInFOV, justAlerted);
}
}
}
}
}
| 10,635 | WandOfLivingEarth | java | en | java | code | {"qsc_code_num_words": 1217, "qsc_code_num_chars": 10635.0, "qsc_code_mean_word_length": 6.1125719, "qsc_code_frac_words_unique": 0.24404273, "qsc_code_frac_chars_top_2grams": 0.02903616, "qsc_code_frac_chars_top_3grams": 0.09705606, "qsc_code_frac_chars_top_4grams": 0.10646592, "qsc_code_frac_chars_dupe_5grams": 0.35166017, "qsc_code_frac_chars_dupe_6grams": 0.28834521, "qsc_code_frac_chars_dupe_7grams": 0.24317785, "qsc_code_frac_chars_dupe_8grams": 0.22368598, "qsc_code_frac_chars_dupe_9grams": 0.19868262, "qsc_code_frac_chars_dupe_10grams": 0.17851862, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01239385, "qsc_code_frac_chars_whitespace": 0.18063, "qsc_code_size_file_byte": 10635.0, "qsc_code_num_lines": 379.0, "qsc_code_num_chars_line_max": 129.0, "qsc_code_num_chars_line_mean": 28.06068602, "qsc_code_frac_chars_alphabet": 0.84128988, "qsc_code_frac_chars_comments": 0.10926187, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.28321678, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.00506703, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00337802, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08041958, "qsc_codejava_score_lines_no_logic": 0.18531469, "qsc_codejava_frac_words_no_modifier": 0.92, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
007idc/LECDN_Crack | README.md | TG[@GoEdge233](https://t.me/goedge233)
# 独家赞助 Goedge
GoEdge CDN
制作自己专属的CDN
利用开源的GoEdge可以零成本制作自己专属的CDN系统,支持集群式管理和API。
https://goedge.cloud
# 感谢Lecdn官方的引流,观察到自开心版PATCH无人使用,故直接开源license服务端源码
## 功能
本仓库可帮助你开心的试用Lecdn
## 使用方法一(直接使用)
安装完Lecdn后从仓库中下载修改过的lecdn-master.patch放到Lecdn目录下
进入Lecdn目录执行指令
```bash
chmod +x lecdn-master.patch
```
完成后执行下面命令修改Hosts
```bash
echo "13.125.122.206 key.lecdn.local">>/etc/hosts
```
## 使用方法二(自行编译)
下载lecdn.zip压缩包,解压放到/license_server目录下。解压后编译运行(需要GOLANG环境)
```bash
go build
./LeCDN
```
完成后执行下面命令修改Hosts($IP改为自己的授权站IP)
```bash
echo "$IP key.lecdn.local">>/etc/hosts
```
## 鸣谢
Lecdn
## 广告位招租 接定制破解 TG[@mihoooyoo](https://t.me/mihoooyoo)
## 许可证
本仓库的代码和文档使用 [Apache 2.0 协议](LICENSE) 授权。 | 729 | README | md | zh | markdown | text | {"qsc_doc_frac_chars_curly_bracket": 0.0, "qsc_doc_frac_words_redpajama_stop": null, "qsc_doc_num_sentences": 18.0, "qsc_doc_num_words": 194, "qsc_doc_num_chars": 729.0, "qsc_doc_num_lines": 57.0, "qsc_doc_mean_word_length": 2.76804124, "qsc_doc_frac_words_full_bracket": 0.0, "qsc_doc_frac_lines_end_with_readmore": 0.0, "qsc_doc_frac_lines_start_with_bullet": 0.0, "qsc_doc_frac_words_unique": 0.58247423, "qsc_doc_entropy_unigram": 4.50976214, "qsc_doc_frac_words_all_caps": 0.04067797, "qsc_doc_frac_lines_dupe_lines": 0.23529412, "qsc_doc_frac_chars_dupe_lines": 0.05943536, "qsc_doc_frac_chars_top_2grams": 0.02234637, "qsc_doc_frac_chars_top_3grams": 0.02979516, "qsc_doc_frac_chars_top_4grams": 0.02607076, "qsc_doc_frac_chars_dupe_5grams": 0.17504655, "qsc_doc_frac_chars_dupe_6grams": 0.05959032, "qsc_doc_frac_chars_dupe_7grams": 0.05959032, "qsc_doc_frac_chars_dupe_8grams": 0.0, "qsc_doc_frac_chars_dupe_9grams": 0.0, "qsc_doc_frac_chars_dupe_10grams": 0.0, "qsc_doc_frac_chars_replacement_symbols": 0.0, "qsc_doc_cate_code_related_file_name": 1.0, "qsc_doc_num_chars_sentence_length_mean": 9.13888889, "qsc_doc_frac_chars_hyperlink_html_tag": 0.06584362, "qsc_doc_frac_chars_alphabet": null, "qsc_doc_frac_chars_digital": 0.02923077, "qsc_doc_frac_chars_whitespace": 0.10836763, "qsc_doc_frac_chars_hex_words": 0.0} | 1 | {"qsc_doc_frac_chars_replacement_symbols": 0, "qsc_doc_entropy_unigram": 0, "qsc_doc_frac_chars_top_2grams": 0, "qsc_doc_frac_chars_top_3grams": 0, "qsc_doc_frac_chars_top_4grams": 0, "qsc_doc_frac_chars_dupe_5grams": 0, "qsc_doc_frac_chars_dupe_6grams": 0, "qsc_doc_frac_chars_dupe_7grams": 0, "qsc_doc_frac_chars_dupe_8grams": 0, "qsc_doc_frac_chars_dupe_9grams": 0, "qsc_doc_frac_chars_dupe_10grams": 0, "qsc_doc_frac_chars_dupe_lines": 0, "qsc_doc_frac_lines_dupe_lines": 0, "qsc_doc_frac_lines_end_with_readmore": 0, "qsc_doc_frac_lines_start_with_bullet": 0, "qsc_doc_frac_words_full_bracket": 0, "qsc_doc_mean_word_length": 0, "qsc_doc_num_chars": 0, "qsc_doc_num_lines": 0, "qsc_doc_num_sentences": 0, "qsc_doc_num_words": 0, "qsc_doc_frac_chars_hex_words": 0, "qsc_doc_frac_chars_hyperlink_html_tag": 0, "qsc_doc_frac_chars_alphabet": 0, "qsc_doc_frac_chars_digital": 0, "qsc_doc_frac_chars_whitespace": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/SuccubusSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.watabou.noosa.TextureFilm;
public class SuccubusSprite extends MobSprite {
public SuccubusSprite() {
super();
texture( Assets.SUCCUBUS );
TextureFilm frames = new TextureFilm( texture, 12, 15 );
idle = new Animation( 8, true );
idle.frames( frames, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 2, 2, 1 );
run = new Animation( 15, true );
run.frames( frames, 3, 4, 5, 6, 7, 8 );
attack = new Animation( 12, false );
attack.frames( frames, 9, 10, 11 );
die = new Animation( 10, false );
die.frames( frames, 12 );
play( idle );
}
@Override
public void die() {
super.die();
emitter().burst( Speck.factory( Speck.HEART ), 6 );
emitter().burst( ShadowParticle.UP, 8 );
}
}
| 1,787 | SuccubusSprite | java | en | java | code | {"qsc_code_num_words": 249, "qsc_code_num_chars": 1787.0, "qsc_code_mean_word_length": 5.04417671, "qsc_code_frac_words_unique": 0.51807229, "qsc_code_frac_chars_top_2grams": 0.02070064, "qsc_code_frac_chars_top_3grams": 0.02866242, "qsc_code_frac_chars_top_4grams": 0.03503185, "qsc_code_frac_chars_dupe_5grams": 0.15764331, "qsc_code_frac_chars_dupe_6grams": 0.05573248, "qsc_code_frac_chars_dupe_7grams": 0.0111465, "qsc_code_frac_chars_dupe_8grams": 0.0111465, "qsc_code_frac_chars_dupe_9grams": 0.0111465, "qsc_code_frac_chars_dupe_10grams": 0.0111465, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.04359862, "qsc_code_frac_chars_whitespace": 0.1913822, "qsc_code_size_file_byte": 1787.0, "qsc_code_num_lines": 58.0, "qsc_code_num_chars_line_max": 85.0, "qsc_code_num_chars_line_mean": 30.81034483, "qsc_code_frac_chars_alphabet": 0.82560554, "qsc_code_frac_chars_comments": 0.43704533, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.03703704, "qsc_codejava_score_lines_no_logic": 0.22222222, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/BurningFistSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
public class BurningFistSprite extends MobSprite {
public BurningFistSprite() {
super();
texture( Assets.BURNING );
TextureFilm frames = new TextureFilm( texture, 24, 17 );
idle = new Animation( 2, true );
idle.frames( frames, 0, 0, 1 );
run = new Animation( 3, true );
run.frames( frames, 0, 1 );
attack = new Animation( 8, false );
attack.frames( frames, 0, 5, 6 );
die = new Animation( 10, false );
die.frames( frames, 0, 2, 3, 4 );
play( idle );
}
private int posToShoot;
@Override
public void attack( int cell ) {
posToShoot = cell;
super.attack( cell );
}
@Override
public void onComplete( Animation anim ) {
if (anim == attack) {
Sample.INSTANCE.play( Assets.SND_ZAP );
MagicMissile.boltFromChar( parent,
MagicMissile.SHADOW,
this,
posToShoot,
new Callback() {
@Override
public void call() {
ch.onAttackComplete();
}
} );
idle();
} else {
super.onComplete( anim );
}
}
}
| 2,098 | BurningFistSprite | java | en | java | code | {"qsc_code_num_words": 266, "qsc_code_num_chars": 2098.0, "qsc_code_mean_word_length": 5.42105263, "qsc_code_frac_words_unique": 0.52255639, "qsc_code_frac_chars_top_2grams": 0.03120666, "qsc_code_frac_chars_top_3grams": 0.03606103, "qsc_code_frac_chars_top_4grams": 0.03952843, "qsc_code_frac_chars_dupe_5grams": 0.05686546, "qsc_code_frac_chars_dupe_6grams": 0.03883495, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02304427, "qsc_code_frac_chars_whitespace": 0.21401335, "qsc_code_size_file_byte": 2098.0, "qsc_code_num_lines": 83.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 25.27710843, "qsc_code_frac_chars_alphabet": 0.85142511, "qsc_code_frac_chars_comments": 0.37225929, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.06382979, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08510638, "qsc_codejava_score_lines_no_logic": 0.23404255, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/MonkSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.noosa.TextureFilm;
import com.watabou.utils.Random;
public class MonkSprite extends MobSprite {
private Animation kick;
public MonkSprite() {
super();
texture( Assets.MONK );
TextureFilm frames = new TextureFilm( texture, 15, 14 );
idle = new Animation( 6, true );
idle.frames( frames, 1, 0, 1, 2 );
run = new Animation( 15, true );
run.frames( frames, 11, 12, 13, 14, 15, 16 );
attack = new Animation( 12, false );
attack.frames( frames, 3, 4, 3, 4 );
kick = new Animation( 10, false );
kick.frames( frames, 5, 6, 5 );
die = new Animation( 15, false );
die.frames( frames, 1, 7, 8, 8, 9, 10 );
play( idle );
}
@Override
public void attack( int cell ) {
super.attack( cell );
if (Random.Float() < 0.5f) {
play( kick );
}
}
@Override
public void onComplete( Animation anim ) {
super.onComplete( anim == kick ? attack : anim );
}
}
| 1,827 | MonkSprite | java | en | java | code | {"qsc_code_num_words": 255, "qsc_code_num_chars": 1827.0, "qsc_code_mean_word_length": 4.89411765, "qsc_code_frac_words_unique": 0.52156863, "qsc_code_frac_chars_top_2grams": 0.04807692, "qsc_code_frac_chars_top_3grams": 0.03125, "qsc_code_frac_chars_top_4grams": 0.04567308, "qsc_code_frac_chars_dupe_5grams": 0.06570513, "qsc_code_frac_chars_dupe_6grams": 0.04487179, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.04308548, "qsc_code_frac_chars_whitespace": 0.21237001, "qsc_code_size_file_byte": 1827.0, "qsc_code_num_lines": 68.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 26.86764706, "qsc_code_frac_chars_alphabet": 0.82418346, "qsc_code_frac_chars_comments": 0.42747674, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05882353, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05882353, "qsc_codejava_score_lines_no_logic": 0.20588235, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/CharSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.effects.DarkBlock;
import com.shatteredpixel.shatteredpixeldungeon.effects.EmoIcon;
import com.shatteredpixel.shatteredpixeldungeon.effects.FloatingText;
import com.shatteredpixel.shatteredpixeldungeon.effects.IceBlock;
import com.shatteredpixel.shatteredpixeldungeon.effects.ShieldHalo;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.effects.Splash;
import com.shatteredpixel.shatteredpixeldungeon.effects.TorchHalo;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.FlameParticle;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ShadowParticle;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.SnowParticle;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.shatteredpixel.shatteredpixeldungeon.ui.CharHealthIndicator;
import com.watabou.glwrap.Matrix;
import com.watabou.glwrap.Vertexbuffer;
import com.watabou.noosa.Camera;
import com.watabou.noosa.Game;
import com.watabou.noosa.MovieClip;
import com.watabou.noosa.NoosaScript;
import com.watabou.noosa.Visual;
import com.watabou.noosa.audio.Sample;
import com.watabou.noosa.particles.Emitter;
import com.watabou.noosa.tweeners.AlphaTweener;
import com.watabou.noosa.tweeners.PosTweener;
import com.watabou.noosa.tweeners.Tweener;
import com.watabou.utils.Callback;
import com.watabou.utils.PointF;
import com.watabou.utils.Random;
public class CharSprite extends MovieClip implements Tweener.Listener, MovieClip.Listener {
// Color constants for floating text
public static final int DEFAULT = 0xFFFFFF;
public static final int POSITIVE = 0x00FF00;
public static final int NEGATIVE = 0xFF0000;
public static final int WARNING = 0xFF8800;
public static final int NEUTRAL = 0xFFFF00;
private static float moveInterval = 0.1f;
private static final float FLASH_INTERVAL = 0.05f;
//the amount the sprite is raised from flat when viewed in a raised perspective
protected float perspectiveRaise = 6 / 16f; //6 pixels
//the width and height of the shadow are a percentage of sprite size
//offset is the number of pixels the shadow is moved down or up (handy for some animations)
protected boolean renderShadow = false;
protected float shadowWidth = 1.2f;
protected float shadowHeight = 0.25f;
protected float shadowOffset = 0.25f;
public enum State {
BURNING, LEVITATING, INVISIBLE, PARALYSED, FROZEN, ILLUMINATED, CHILLED, DARKENED, MARKED, HEALING, SHIELDED
}
protected Animation idle;
protected Animation run;
protected Animation attack;
protected Animation operate;
protected Animation zap;
protected Animation die;
protected Callback animCallback;
protected PosTweener motion;
protected Emitter burning;
protected Emitter chilled;
protected Emitter marked;
protected Emitter levitation;
protected Emitter healing;
protected IceBlock iceBlock;
protected DarkBlock darkBlock;
protected TorchHalo light;
protected ShieldHalo shield;
protected AlphaTweener invisible;
protected EmoIcon emo;
protected CharHealthIndicator health;
private Tweener jumpTweener;
private Callback jumpCallback;
protected float flashTime = 0;
protected boolean sleeping = false;
public Char ch;
//used to prevent the actor associated with this sprite from acting until movement completes
public volatile boolean isMoving = false;
public CharSprite() {
super();
listener = this;
}
@Override
public void play(Animation anim) {
//Shouldn't interrupt the dieing animation
if (curAnim == null || curAnim != die) {
super.play(anim);
}
}
//intended to be used for placing a character in the game world
public void link( Char ch ) {
linkVisuals( ch );
this.ch = ch;
ch.sprite = this;
place( ch.pos );
turnTo( ch.pos, Random.Int( Dungeon.level.length() ) );
renderShadow = true;
if (ch != Dungeon.hero) {
if (health == null) {
health = new CharHealthIndicator(ch);
} else {
health.target(ch);
}
}
ch.updateSpriteState();
}
//used for just updating a sprite based on a given character, not linking them or placing in the game
public void linkVisuals( Char ch ){
//do nothin by default
}
public PointF worldToCamera( int cell ) {
final int csize = DungeonTilemap.SIZE;
return new PointF(
PixelScene.align(Camera.main, ((cell % Dungeon.level.width()) + 0.5f) * csize - width * 0.5f),
PixelScene.align(Camera.main, ((cell / Dungeon.level.width()) + 1.0f) * csize - height - csize * perspectiveRaise)
);
}
public void place( int cell ) {
point( worldToCamera( cell ) );
}
public void showStatus( int color, String text, Object... args ) {
if (visible) {
if (args.length > 0) {
text = Messages.format( text, args );
}
if (ch != null) {
FloatingText.show( x + width * 0.5f, y, ch.pos, text, color );
} else {
FloatingText.show( x + width * 0.5f, y, text, color );
}
}
}
public void idle() {
play(idle);
}
public void move( int from, int to ) {
turnTo( from , to );
play( run );
motion = new PosTweener( this, worldToCamera( to ), moveInterval);
motion.listener = this;
parent.add( motion );
isMoving = true;
if (visible && Dungeon.level.water[from] && !ch.flying) {
GameScene.ripple( from );
}
}
public static void setMoveInterval( float interval){
moveInterval = interval;
}
//returns where the center of this sprite will be after it completes any motion in progress
public PointF destinationCenter(){
if (motion != null){
return new PointF(motion.end.x + width()/2f, motion.end.y + height()/2f);
} else {
return center();
}
}
public void interruptMotion() {
if (motion != null) {
motion.stop(false);
}
}
public void attack( int cell ) {
turnTo( ch.pos, cell );
play( attack );
}
public void attack( int cell, Callback callback ) {
animCallback = callback;
turnTo( ch.pos, cell );
play( attack );
}
public void operate( int cell ) {
turnTo( ch.pos, cell );
play( operate );
}
public void operate( int cell, Callback callback ) {
animCallback = callback;
turnTo( ch.pos, cell );
play( operate );
}
public void zap( int cell ) {
turnTo( ch.pos, cell );
play( zap );
}
public void zap( int cell, Callback callback ) {
animCallback = callback;
zap( cell );
}
public void turnTo( int from, int to ) {
int fx = from % Dungeon.level.width();
int tx = to % Dungeon.level.width();
if (tx > fx) {
flipHorizontal = false;
} else if (tx < fx) {
flipHorizontal = true;
}
}
public void jump( int from, int to, Callback callback ) {
jumpCallback = callback;
int distance = Dungeon.level.distance( from, to );
jumpTweener = new JumpTweener( this, worldToCamera( to ), distance * 4, distance * 0.1f );
jumpTweener.listener = this;
parent.add( jumpTweener );
turnTo( from, to );
}
public void die() {
sleeping = false;
play( die );
if (emo != null) {
emo.killAndErase();
}
if (health != null){
health.killAndErase();
}
}
public Emitter emitter() {
Emitter emitter = GameScene.emitter();
emitter.pos( this );
return emitter;
}
public Emitter centerEmitter() {
Emitter emitter = GameScene.emitter();
emitter.pos( center() );
return emitter;
}
public Emitter bottomEmitter() {
Emitter emitter = GameScene.emitter();
emitter.pos( x, y + height, width, 0 );
return emitter;
}
public void burst( final int color, int n ) {
if (visible) {
Splash.at( center(), color, n );
}
}
public void bloodBurstA( PointF from, int damage ) {
if (visible) {
PointF c = center();
int n = (int)Math.min( 9 * Math.sqrt( (double)damage / ch.HT ), 9 );
Splash.at( c, PointF.angle( from, c ), 3.1415926f / 2, blood(), n );
}
}
public int blood() {
return 0xFFBB0000;
}
public void flash() {
ra = ba = ga = 1f;
flashTime = FLASH_INTERVAL;
}
public void add( State state ) {
switch (state) {
case BURNING:
burning = emitter();
burning.pour( FlameParticle.FACTORY, 0.06f );
if (visible) {
Sample.INSTANCE.play( Assets.SND_BURNING );
}
break;
case LEVITATING:
levitation = emitter();
levitation.pour( Speck.factory( Speck.JET ), 0.02f );
break;
case INVISIBLE:
if (invisible != null) {
invisible.killAndErase();
}
invisible = new AlphaTweener( this, 0.4f, 0.4f );
if (parent != null){
parent.add(invisible);
} else
alpha( 0.4f );
break;
case PARALYSED:
paused = true;
break;
case FROZEN:
iceBlock = IceBlock.freeze( this );
paused = true;
break;
case ILLUMINATED:
GameScene.effect( light = new TorchHalo( this ) );
break;
case CHILLED:
chilled = emitter();
chilled.pour(SnowParticle.FACTORY, 0.1f);
break;
case DARKENED:
darkBlock = DarkBlock.darken( this );
break;
case MARKED:
marked = emitter();
marked.pour(ShadowParticle.UP, 0.1f);
break;
case HEALING:
healing = emitter();
healing.pour(Speck.factory(Speck.HEALING), 0.5f);
break;
case SHIELDED:
GameScene.effect( shield = new ShieldHalo( this ));
break;
}
}
public void remove( State state ) {
switch (state) {
case BURNING:
if (burning != null) {
burning.on = false;
burning = null;
}
break;
case LEVITATING:
if (levitation != null) {
levitation.on = false;
levitation = null;
}
break;
case INVISIBLE:
if (invisible != null) {
invisible.killAndErase();
invisible = null;
}
alpha( 1f );
break;
case PARALYSED:
paused = false;
break;
case FROZEN:
if (iceBlock != null) {
iceBlock.melt();
iceBlock = null;
}
paused = false;
break;
case ILLUMINATED:
if (light != null) {
light.putOut();
}
break;
case CHILLED:
if (chilled != null){
chilled.on = false;
chilled = null;
}
break;
case DARKENED:
if (darkBlock != null) {
darkBlock.lighten();
darkBlock = null;
}
break;
case MARKED:
if (marked != null){
marked.on = false;
marked = null;
}
break;
case HEALING:
if (healing != null){
healing.on = false;
healing = null;
}
break;
case SHIELDED:
if (shield != null){
shield.putOut();
}
break;
}
}
@Override
//syncronized due to EmoIcon handling
public synchronized void update() {
super.update();
if (paused && listener != null) {
listener.onComplete( curAnim );
}
if (flashTime > 0 && (flashTime -= Game.elapsed) <= 0) {
resetColor();
}
if (burning != null) {
burning.visible = visible;
}
if (levitation != null) {
levitation.visible = visible;
}
if (iceBlock != null) {
iceBlock.visible = visible;
}
if (chilled != null) {
chilled.visible = visible;
}
if (marked != null) {
marked.visible = visible;
}
if (sleeping) {
showSleep();
} else {
hideSleep();
}
if (emo != null && emo.alive) {
emo.visible = visible;
}
}
@Override
public void resetColor() {
super.resetColor();
if (invisible != null){
alpha(0.4f);
}
}
public synchronized void showSleep() {
if (emo instanceof EmoIcon.Sleep) {
} else {
if (emo != null) {
emo.killAndErase();
}
emo = new EmoIcon.Sleep( this );
emo.visible = visible;
}
idle();
}
public synchronized void hideSleep() {
if (emo instanceof EmoIcon.Sleep) {
emo.killAndErase();
emo = null;
}
}
public synchronized void showAlert() {
if (emo instanceof EmoIcon.Alert) {
} else {
if (emo != null) {
emo.killAndErase();
}
emo = new EmoIcon.Alert( this );
emo.visible = visible;
}
}
public synchronized void hideAlert() {
if (emo instanceof EmoIcon.Alert) {
emo.killAndErase();
emo = null;
}
}
public synchronized void showLost() {
if (emo instanceof EmoIcon.Lost) {
} else {
if (emo != null) {
emo.killAndErase();
}
emo = new EmoIcon.Lost( this );
emo.visible = visible;
}
}
public synchronized void hideLost() {
if (emo instanceof EmoIcon.Lost) {
emo.killAndErase();
emo = null;
}
}
@Override
public void kill() {
super.kill();
if (emo != null) {
emo.killAndErase();
}
for( State s : State.values()){
remove(s);
}
if (health != null){
health.killAndErase();
}
}
private float[] shadowMatrix = new float[16];
@Override
protected void updateMatrix() {
super.updateMatrix();
Matrix.copy(matrix, shadowMatrix);
Matrix.translate(shadowMatrix,
(width() * (1f - shadowWidth)) / 2f,
(height() * (1f - shadowHeight)) + shadowOffset);
Matrix.scale(shadowMatrix, shadowWidth, shadowHeight);
}
@Override
public void draw() {
if (texture == null || (!dirty && buffer == null))
return;
if (renderShadow) {
if (dirty) {
verticesBuffer.position(0);
verticesBuffer.put(vertices);
if (buffer == null)
buffer = new Vertexbuffer(verticesBuffer);
else
buffer.updateVertices(verticesBuffer);
dirty = false;
}
NoosaScript script = script();
texture.bind();
script.camera(camera());
updateMatrix();
script.uModel.valueM4(shadowMatrix);
script.lighting(
0, 0, 0, am * .6f,
0, 0, 0, aa * .6f);
script.drawQuad(buffer);
}
super.draw();
}
@Override
public void onComplete( Tweener tweener ) {
if (tweener == jumpTweener) {
if (visible && Dungeon.level.water[ch.pos] && !ch.flying) {
GameScene.ripple( ch.pos );
}
if (jumpCallback != null) {
jumpCallback.call();
}
} else if (tweener == motion) {
synchronized (this) {
isMoving = false;
motion.killAndErase();
motion = null;
ch.onMotionComplete();
notifyAll();
}
}
}
@Override
public void onComplete( Animation anim ) {
if (animCallback != null) {
Callback executing = animCallback;
animCallback = null;
executing.call();
} else {
if (anim == attack) {
idle();
ch.onAttackComplete();
} else if (anim == operate) {
idle();
ch.onOperateComplete();
}
}
}
private static class JumpTweener extends Tweener {
public Visual visual;
public PointF start;
public PointF end;
public float height;
public JumpTweener( Visual visual, PointF pos, float height, float time ) {
super( visual, time );
this.visual = visual;
start = visual.point();
end = pos;
this.height = height;
}
@Override
protected void updateValues( float progress ) {
visual.point( PointF.inter( start, end, progress ).offset( 0, -height * 4 * progress * (1 - progress) ) );
}
}
}
| 16,028 | CharSprite | java | en | java | code | {"qsc_code_num_words": 1825, "qsc_code_num_chars": 16028.0, "qsc_code_mean_word_length": 5.82027397, "qsc_code_frac_words_unique": 0.22520548, "qsc_code_frac_chars_top_2grams": 0.02880813, "qsc_code_frac_chars_top_3grams": 0.07154961, "qsc_code_frac_chars_top_4grams": 0.07870458, "qsc_code_frac_chars_dupe_5grams": 0.21568443, "qsc_code_frac_chars_dupe_6grams": 0.12219921, "qsc_code_frac_chars_dupe_7grams": 0.07861043, "qsc_code_frac_chars_dupe_8grams": 0.05356807, "qsc_code_frac_chars_dupe_9grams": 0.0351158, "qsc_code_frac_chars_dupe_10grams": 0.01167388, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01033902, "qsc_code_frac_chars_whitespace": 0.22154979, "qsc_code_size_file_byte": 16028.0, "qsc_code_num_lines": 702.0, "qsc_code_num_chars_line_max": 118.0, "qsc_code_num_chars_line_mean": 22.83190883, "qsc_code_frac_chars_alphabet": 0.84098742, "qsc_code_frac_chars_comments": 0.0943973, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.25812274, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.00344471, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.066787, "qsc_codejava_score_lines_no_logic": 0.18772563, "qsc_codejava_frac_words_no_modifier": 0.94736842, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/StatueSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.watabou.noosa.TextureFilm;
public class StatueSprite extends MobSprite {
public StatueSprite() {
super();
texture( Assets.STATUE );
TextureFilm frames = new TextureFilm( texture, 12, 15 );
idle = new Animation( 2, true );
idle.frames( frames, 0, 0, 0, 0, 0, 1, 1 );
run = new Animation( 15, true );
run.frames( frames, 2, 3, 4, 5, 6, 7 );
attack = new Animation( 12, false );
attack.frames( frames, 8, 9, 10 );
die = new Animation( 5, false );
die.frames( frames, 11, 12, 13, 14, 15, 15 );
play( idle );
}
@Override
public int blood() {
return 0xFFcdcdb7;
}
}
| 1,525 | StatueSprite | java | en | java | code | {"qsc_code_num_words": 216, "qsc_code_num_chars": 1525.0, "qsc_code_mean_word_length": 4.90740741, "qsc_code_frac_words_unique": 0.5787037, "qsc_code_frac_chars_top_2grams": 0.04528302, "qsc_code_frac_chars_top_3grams": 0.03679245, "qsc_code_frac_chars_top_4grams": 0.05377358, "qsc_code_frac_chars_dupe_5grams": 0.07735849, "qsc_code_frac_chars_dupe_6grams": 0.05283019, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.04801325, "qsc_code_frac_chars_whitespace": 0.20786885, "qsc_code_size_file_byte": 1525.0, "qsc_code_num_lines": 54.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 28.24074074, "qsc_code_frac_chars_alphabet": 0.8294702, "qsc_code_frac_chars_comments": 0.51213115, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.01344086, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.04347826, "qsc_codejava_score_lines_no_logic": 0.2173913, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/WandmakerSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.effects.ShieldHalo;
import com.shatteredpixel.shatteredpixeldungeon.effects.particles.ElmoParticle;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.audio.Sample;
public class WandmakerSprite extends MobSprite {
private ShieldHalo shield;
public WandmakerSprite() {
super();
texture( Assets.MAKER );
TextureFilm frames = new TextureFilm( texture, 12, 14 );
idle = new Animation( 10, true );
idle.frames( frames, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 2, 1 );
run = new Animation( 20, true );
run.frames( frames, 0 );
die = new Animation( 20, false );
die.frames( frames, 0 );
play( idle );
}
@Override
public void link( Char ch ) {
super.link( ch );
add(State.SHIELDED);
}
@Override
public void die() {
super.die();
remove(State.SHIELDED);
emitter().start( ElmoParticle.FACTORY, 0.03f, 60 );
if (visible) {
Sample.INSTANCE.play( Assets.SND_BURNING );
}
}
}
| 1,982 | WandmakerSprite | java | en | java | code | {"qsc_code_num_words": 270, "qsc_code_num_chars": 1982.0, "qsc_code_mean_word_length": 5.21481481, "qsc_code_frac_words_unique": 0.51111111, "qsc_code_frac_chars_top_2grams": 0.01846591, "qsc_code_frac_chars_top_3grams": 0.02556818, "qsc_code_frac_chars_top_4grams": 0.03125, "qsc_code_frac_chars_dupe_5grams": 0.14488636, "qsc_code_frac_chars_dupe_6grams": 0.04971591, "qsc_code_frac_chars_dupe_7grams": 0.00994318, "qsc_code_frac_chars_dupe_8grams": 0.00994318, "qsc_code_frac_chars_dupe_9grams": 0.00994318, "qsc_code_frac_chars_dupe_10grams": 0.00994318, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.03593556, "qsc_code_frac_chars_whitespace": 0.18567104, "qsc_code_size_file_byte": 1982.0, "qsc_code_num_lines": 71.0, "qsc_code_num_chars_line_max": 97.0, "qsc_code_num_chars_line_mean": 27.91549296, "qsc_code_frac_chars_alphabet": 0.83643123, "qsc_code_frac_chars_comments": 0.39404642, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05555556, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.05555556, "qsc_codejava_score_lines_no_logic": 0.27777778, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/sprites/WarlockSprite.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.sprites;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Warlock;
import com.shatteredpixel.shatteredpixeldungeon.effects.MagicMissile;
import com.watabou.noosa.TextureFilm;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
public class WarlockSprite extends MobSprite {
public WarlockSprite() {
super();
texture( Assets.WARLOCK );
TextureFilm frames = new TextureFilm( texture, 12, 15 );
idle = new Animation( 2, true );
idle.frames( frames, 0, 0, 0, 1, 0, 0, 1, 1 );
run = new Animation( 15, true );
run.frames( frames, 0, 2, 3, 4 );
attack = new Animation( 12, false );
attack.frames( frames, 0, 5, 6 );
zap = attack.clone();
die = new Animation( 15, false );
die.frames( frames, 0, 7, 8, 8, 9, 10 );
play( idle );
}
public void zap( int cell ) {
turnTo( ch.pos , cell );
play( zap );
MagicMissile.boltFromChar( parent,
MagicMissile.SHADOW,
this,
cell,
new Callback() {
@Override
public void call() {
((Warlock)ch).onZapComplete();
}
} );
Sample.INSTANCE.play( Assets.SND_ZAP );
}
@Override
public void onComplete( Animation anim ) {
if (anim == zap) {
idle();
}
super.onComplete( anim );
}
}
| 2,146 | WarlockSprite | java | en | java | code | {"qsc_code_num_words": 282, "qsc_code_num_chars": 2146.0, "qsc_code_mean_word_length": 5.22695035, "qsc_code_frac_words_unique": 0.5070922, "qsc_code_frac_chars_top_2grams": 0.03663501, "qsc_code_frac_chars_top_3grams": 0.10312076, "qsc_code_frac_chars_top_4grams": 0.03867028, "qsc_code_frac_chars_dupe_5grams": 0.05563094, "qsc_code_frac_chars_dupe_6grams": 0.03799186, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02935995, "qsc_code_frac_chars_whitespace": 0.20643057, "qsc_code_size_file_byte": 2146.0, "qsc_code_num_lines": 81.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 26.49382716, "qsc_code_frac_chars_alphabet": 0.83617146, "qsc_code_frac_chars_comments": 0.3639329, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.04347826, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.08695652, "qsc_codejava_score_lines_no_logic": 0.23913043, "qsc_codejava_frac_words_no_modifier": 0.6, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfCorrosiveGas.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.CorrosiveGas;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.audio.Sample;
public class PotionOfCorrosiveGas extends ExoticPotion {
{
initials = 11;
}
@Override
public void shatter( int cell ) {
if (Dungeon.level.heroFOV[cell]) {
setKnown();
splash( cell );
Sample.INSTANCE.play( Assets.SND_SHATTER );
}
GameScene.add( Blob.seed( cell, 200, CorrosiveGas.class ).setStrength( 1 + Dungeon.depth/5));
}
}
| 1,578 | PotionOfCorrosiveGas | java | en | java | code | {"qsc_code_num_words": 204, "qsc_code_num_chars": 1578.0, "qsc_code_mean_word_length": 5.85784314, "qsc_code_frac_words_unique": 0.59803922, "qsc_code_frac_chars_top_2grams": 0.08535565, "qsc_code_frac_chars_top_3grams": 0.19079498, "qsc_code_frac_chars_top_4grams": 0.18410042, "qsc_code_frac_chars_dupe_5grams": 0.16066946, "qsc_code_frac_chars_dupe_6grams": 0.13891213, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01805869, "qsc_code_frac_chars_whitespace": 0.15779468, "qsc_code_size_file_byte": 1578.0, "qsc_code_num_lines": 49.0, "qsc_code_num_chars_line_max": 96.0, "qsc_code_num_chars_line_mean": 32.20408163, "qsc_code_frac_chars_alphabet": 0.88111362, "qsc_code_frac_chars_comments": 0.49429658, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.04761905, "qsc_codejava_score_lines_no_logic": 0.38095238, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/LightAquaBlue/BBMutableOBEXHeaderSet.h | /*
* Copyright (c) 2009 Bea Lam. All rights reserved.
*
* This file is part of LightBlue.
*
* LightBlue is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LightBlue is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
*/
//
// BBMutableOBEXHeaderSet.h
// LightAquaBlue
//
// A mutable version of BBOBEXHeaderSet that allows adding and removing
// of headers.
//
#import "BBOBEXHeaderSet.h"
@interface BBMutableOBEXHeaderSet : BBOBEXHeaderSet {
CFMutableDictionaryRef mMutableDict;
}
/*
* Creates and returns an empty header set.
*/
+ (id)headerSet;
/*
* Removes the header <headerID> from this header set.
*/
- (void)removeValueForHeader:(uint8_t)headerID;
/*
* Sets the value for the Name header to <name>, overriding any existing
* value for this header.
*/
- (void)setValueForNameHeader:(NSString *)name;
/*
* Sets the value for the Type header to <type>, overriding any existing
* value for this header.
*/
- (void)setValueForTypeHeader:(NSString *)type;
/*
* Sets the value for the Length header to <length>, overriding any existing
* value for this header.
*/
- (void)setValueForLengthHeader:(uint32_t)length;
/*
* Sets the value for the Time (0x44) header to <date>, overriding any
* existing value for this header. Assumes <date> is in local time.
*/
- (void)setValueForTimeHeader:(NSDate *)date;
/*
* Sets the value for the Time (0x44) header to <date>, overriding any
* existing value for this header. If <isUTCTime> is YES, the time value is
* marked as UTC time, otherwise it is marked as local time.
*/
- (void)setValueForTimeHeader:(NSDate *)date isUTCTime:(BOOL)isUTCTime;
/*
* Sets the value for the Description header to <description>, overriding
* any existing value for this header.
*/
- (void)setValueForDescriptionHeader:(NSString *)description;
/*
* Sets the value for the Target header to <target>, overriding
* any existing value for this header.
*/
- (void)setValueForTargetHeader:(NSData *)target;
/*
* Sets the value for the HTTP header to <http>, overriding
* any existing value for this header.
*/
- (void)setValueForHTTPHeader:(NSData *)http;
/*
* Sets the value for the Who header to <who>, overriding
* any existing value for this header.
*/
- (void)setValueForWhoHeader:(NSData *)who;
/*
* Sets the value for the Connection Id header to <connectionID>, overriding
* any existing value for this header.
*/
- (void)setValueForConnectionIDHeader:(uint32_t)connectionID;
/*
* Sets the value for the Application Parameters header to <appParameters>,
* overriding any existing value for this header.
*/
- (void)setValueForApplicationParametersHeader:(NSData *)appParameters;
/*
* Sets the value for the Authorization Challenge header to <authChallenge>,
* overriding any existing value for this header.
*/
- (void)setValueForAuthorizationChallengeHeader:(NSData *)authChallenge;
/*
* Sets the value for the Authorization Response header to <authResponse>,
* overriding any existing value for this header.
*/
- (void)setValueForAuthorizationResponseHeader:(NSData *)authResponse;
/*
* Sets the value for the Object Class header to <objectClass>,
* overriding any existing value for this header.
*/
- (void)setValueForObjectClassHeader:(NSData *)objectClass;
/*
* Sets the value for the unicode-encoded header <headerID> to <value>,
* overriding any existing value for this header.
*/
- (void)setValue:(NSString *)value forUnicodeHeader:(uint8_t)headerID;
/*
* Sets the value for the byte-sequence-encoded header <headerID> to <value>,
* overriding any existing value for this header.
*/
- (void)setValue:(NSData *)value forByteSequenceHeader:(uint8_t)headerID;
/*
* Sets the value for the 4-byte-header <headerID> to <value>,
* overriding any existing value for this header.
*/
- (void)setValue:(uint32_t)value for4ByteHeader:(uint8_t)headerID;
/*
* Sets the value for the 1-byte-encoded header <headerID> to <value>,
* overriding any existing value for this header.
*/
- (void)setValue:(uint8_t)value for1ByteHeader:(uint8_t)headerID;
/*
* Adds the headers from <headerSet> to this header set.
*/
- (void)addHeadersFromHeaderSet:(BBOBEXHeaderSet *)headerSet;
/*
* Adds the headers from <headersData> to this header set. <length> specifies
* the size of <headersData>.
*
* Returns NO if there was an error parsing the <headersData>.
*/
- (BOOL)addHeadersFromHeadersData:(const uint8_t *)headersData
length:(size_t)length;
@end
| 5,009 | BBMutableOBEXHeaderSet | h | en | c | code | {"qsc_code_num_words": 634, "qsc_code_num_chars": 5009.0, "qsc_code_mean_word_length": 5.74763407, "qsc_code_frac_words_unique": 0.28233438, "qsc_code_frac_chars_top_2grams": 0.07903403, "qsc_code_frac_chars_top_3grams": 0.05927552, "qsc_code_frac_chars_top_4grams": 0.0740944, "qsc_code_frac_chars_dupe_5grams": 0.41684962, "qsc_code_frac_chars_dupe_6grams": 0.36031833, "qsc_code_frac_chars_dupe_7grams": 0.30378705, "qsc_code_frac_chars_dupe_8grams": 0.30378705, "qsc_code_frac_chars_dupe_9grams": 0.12705818, "qsc_code_frac_chars_dupe_10grams": 0.12705818, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00672592, "qsc_code_frac_chars_whitespace": 0.16889599, "qsc_code_size_file_byte": 5009.0, "qsc_code_num_lines": 168.0, "qsc_code_num_chars_line_max": 79.0, "qsc_code_num_chars_line_mean": 29.81547619, "qsc_code_frac_chars_alphabet": 0.86860437, "qsc_code_frac_chars_comments": 0.70013975, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.01131824, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codec_frac_lines_func_ratio": 0.0, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 0.0, "qsc_codec_score_lines_no_logic": 0.0, "qsc_codec_frac_lines_print": 0.0, "qsc_codec_frac_lines_preprocessor_directives": null} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 0, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
0-1-0/lightblue-0.4 | src/mac/LightAquaBlue/BBStreamingOutputStream.h | /*
* Copyright (c) 2009 Bea Lam. All rights reserved.
*
* This file is part of LightBlue.
*
* LightBlue is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LightBlue is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LightBlue. If not, see <http://www.gnu.org/licenses/>.
*/
//
// BBStreamingOutputStream.h
// LightAquaBlue
//
// A NSOutputStream subclass that calls write: on its delegate when data
// is available.
// This class is only intended for use from the LightBlue library.
// Most methods are not implemented, and there are no stream:HandleEvent:
// calls to the delegate.
//
#import <Cocoa/Cocoa.h>
@interface BBStreamingOutputStream : NSOutputStream {
id mDelegate;
NSStreamStatus mStatus;
}
- (id)initWithDelegate:(id)delegate;
@end
@protocol BBStreamingOutputStreamDelegate
- (int)write:(NSData *)data;
@end
| 1,309 | BBStreamingOutputStream | h | en | c | code | {"qsc_code_num_words": 180, "qsc_code_num_chars": 1309.0, "qsc_code_mean_word_length": 5.34444444, "qsc_code_frac_words_unique": 0.64444444, "qsc_code_frac_chars_top_2grams": 0.01559252, "qsc_code_frac_chars_top_3grams": 0.04054054, "qsc_code_frac_chars_top_4grams": 0.05925156, "qsc_code_frac_chars_dupe_5grams": 0.08523909, "qsc_code_frac_chars_dupe_6grams": 0.05821206, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00468604, "qsc_code_frac_chars_whitespace": 0.18487395, "qsc_code_size_file_byte": 1309.0, "qsc_code_num_lines": 47.0, "qsc_code_num_chars_line_max": 76.0, "qsc_code_num_chars_line_mean": 27.85106383, "qsc_code_frac_chars_alphabet": 0.89690722, "qsc_code_frac_chars_comments": 0.80595875, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.2, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codec_frac_lines_func_ratio": 0.0, "qsc_codec_cate_bitsstdc": 0.0, "qsc_codec_nums_lines_main": 0, "qsc_codec_frac_lines_goto": 0.0, "qsc_codec_cate_var_zero": 0.0, "qsc_codec_score_lines_no_logic": 0.0, "qsc_codec_frac_lines_print": 0.0, "qsc_codec_frac_lines_preprocessor_directives": null} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 1, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codec_frac_lines_func_ratio": 0, "qsc_codec_nums_lines_main": 0, "qsc_codec_score_lines_no_logic": 0, "qsc_codec_frac_lines_preprocessor_directives": 0, "qsc_codec_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfStormClouds.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.StormCloud;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.noosa.audio.Sample;
public class PotionOfStormClouds extends ExoticPotion {
{
initials = 5;
}
@Override
public void shatter(int cell) {
if (Dungeon.level.heroFOV[cell]) {
setKnown();
splash( cell );
Sample.INSTANCE.play( Assets.SND_SHATTER );
}
GameScene.add( Blob.seed( cell, 1000, StormCloud.class ) );
}
}
| 1,538 | PotionOfStormClouds | java | en | java | code | {"qsc_code_num_words": 199, "qsc_code_num_chars": 1538.0, "qsc_code_mean_word_length": 5.85427136, "qsc_code_frac_words_unique": 0.59296482, "qsc_code_frac_chars_top_2grams": 0.08755365, "qsc_code_frac_chars_top_3grams": 0.19570815, "qsc_code_frac_chars_top_4grams": 0.1888412, "qsc_code_frac_chars_dupe_5grams": 0.16480687, "qsc_code_frac_chars_dupe_6grams": 0.14248927, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01701469, "qsc_code_frac_chars_whitespace": 0.15929779, "qsc_code_size_file_byte": 1538.0, "qsc_code_num_lines": 49.0, "qsc_code_num_chars_line_max": 73.0, "qsc_code_num_chars_line_mean": 31.3877551, "qsc_code_frac_chars_alphabet": 0.88399072, "qsc_code_frac_chars_comments": 0.50715215, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.04761905, "qsc_codejava_score_lines_no_logic": 0.38095238, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfEarthenArmor.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Barkskin;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
public class PotionOfEarthenArmor extends ExoticPotion {
{
initials = 8;
}
@Override
public void apply( Hero hero ) {
setKnown();
Buff.affect(hero, Barkskin.class).set( 2 + hero.lvl/3, 50 );
}
}
| 1,274 | PotionOfEarthenArmor | java | en | java | code | {"qsc_code_num_words": 174, "qsc_code_num_chars": 1274.0, "qsc_code_mean_word_length": 5.50574713, "qsc_code_frac_words_unique": 0.6091954, "qsc_code_frac_chars_top_2grams": 0.07098121, "qsc_code_frac_chars_top_3grams": 0.15866388, "qsc_code_frac_chars_top_4grams": 0.05949896, "qsc_code_frac_chars_dupe_5grams": 0.2526096, "qsc_code_frac_chars_dupe_6grams": 0.17327766, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02077432, "qsc_code_frac_chars_whitespace": 0.16875981, "qsc_code_size_file_byte": 1274.0, "qsc_code_num_lines": 41.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 31.07317073, "qsc_code_frac_chars_alphabet": 0.88385269, "qsc_code_frac_chars_comments": 0.6122449, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.07142857, "qsc_codejava_score_lines_no_logic": 0.35714286, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/exotic/PotionOfHolyFuror.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.potions.exotic;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Bless;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
public class PotionOfHolyFuror extends ExoticPotion {
{
initials = 0;
}
@Override
public void apply( Hero hero ) {
setKnown();
Buff.prolong(hero, Bless.class, 100f);
}
}
| 1,243 | PotionOfHolyFuror | java | en | java | code | {"qsc_code_num_words": 169, "qsc_code_num_chars": 1243.0, "qsc_code_mean_word_length": 5.56213018, "qsc_code_frac_words_unique": 0.60946746, "qsc_code_frac_chars_top_2grams": 0.07234043, "qsc_code_frac_chars_top_3grams": 0.16170213, "qsc_code_frac_chars_top_4grams": 0.0606383, "qsc_code_frac_chars_dupe_5grams": 0.25744681, "qsc_code_frac_chars_dupe_6grams": 0.17659574, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.02028986, "qsc_code_frac_chars_whitespace": 0.16733709, "qsc_code_size_file_byte": 1243.0, "qsc_code_num_lines": 40.0, "qsc_code_num_chars_line_max": 72.0, "qsc_code_num_chars_line_mean": 31.075, "qsc_code_frac_chars_alphabet": 0.88792271, "qsc_code_frac_chars_comments": 0.62751408, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.07142857, "qsc_codejava_score_lines_no_logic": 0.35714286, "qsc_codejava_frac_words_no_modifier": 0.5, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/items/potions/brews/BlizzardBrew.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items.potions.brews;
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blizzard;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.AlchemicalCatalyst;
import com.shatteredpixel.shatteredpixeldungeon.items.potions.PotionOfFrost;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.watabou.noosa.audio.Sample;
public class BlizzardBrew extends Brew {
{
image = ItemSpriteSheet.BREW_BLIZZARD;
}
@Override
public void shatter(int cell) {
if (Dungeon.level.heroFOV[cell]) {
splash( cell );
Sample.INSTANCE.play( Assets.SND_SHATTER );
}
GameScene.add( Blob.seed( cell, 1000, Blizzard.class ) );
}
@Override
public int price() {
//prices of ingredients
return quantity * (30 + 40);
}
public static class Recipe extends com.shatteredpixel.shatteredpixeldungeon.items.Recipe.SimpleRecipe {
{
inputs = new Class[]{PotionOfFrost.class, AlchemicalCatalyst.class};
inQuantity = new int[]{1, 1};
cost = 6;
output = BlizzardBrew.class;
outQuantity = 1;
}
}
}
| 2,151 | BlizzardBrew | java | en | java | code | {"qsc_code_num_words": 261, "qsc_code_num_chars": 2151.0, "qsc_code_mean_word_length": 6.25287356, "qsc_code_frac_words_unique": 0.52873563, "qsc_code_frac_chars_top_2grams": 0.10416667, "qsc_code_frac_chars_top_3grams": 0.23284314, "qsc_code_frac_chars_top_4grams": 0.21568627, "qsc_code_frac_chars_dupe_5grams": 0.21691176, "qsc_code_frac_chars_dupe_6grams": 0.17034314, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01593407, "qsc_code_frac_chars_whitespace": 0.15388192, "qsc_code_size_file_byte": 2151.0, "qsc_code_num_lines": 69.0, "qsc_code_num_chars_line_max": 105.0, "qsc_code_num_chars_line_mean": 31.17391304, "qsc_code_frac_chars_alphabet": 0.88076923, "qsc_code_frac_chars_comments": 0.37331474, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.05555556, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 1.0, "qsc_codejava_frac_lines_func_ratio": 0.05555556, "qsc_codejava_score_lines_no_logic": 0.33333333, "qsc_codejava_frac_words_no_modifier": 0.66666667, "qsc_codejava_frac_words_legal_var_name": null, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 1, "qsc_code_frac_chars_top_4grams": 1, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 1, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
00JCIV00/cova | build.zig | const std = @import("std");
pub const generate = @import("src/generate.zig");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
//const build_options = b.addOptions();
const bin_name = b.option([]const u8, "name", "A name for the binary being created.");
b.exe_dir = "./bin";
// Modules & Artifacts
// - Lib Module
const cova_mod = b.addModule("cova", .{
.root_source_file = b.path("src/cova.zig"),
});
// - Meta Module (for Docs and Tests)
const cova_meta_mod = b.addModule("cova", .{
.root_source_file = b.path("src/cova.zig"),
.target = target,
.optimize = optimize,
});
// - Generator Artifact
_ = b.addModule("cova_gen", .{
.root_source_file = b.path("src/generator.zig"),
});
// Library (Used for Docs)
const cova_lib = b.addLibrary(.{
.name = "cova",
.linkage = .static,
.root_module = cova_meta_mod,
});
// Tests
const cova_tests = b.addTest(.{ .root_module = cova_meta_mod });
const run_cova_tests = b.addRunArtifact(cova_tests);
const test_step = b.step("test", "Run the cova library tests");
test_step.dependOn(&run_cova_tests.step);
// Docs
const build_docs = b.addInstallDirectory(.{
.source_dir = cova_lib.getEmittedDocs(),
.install_dir = .prefix,
.install_subdir = "../docs",
});
const build_docs_step = b.step("docs", "Build the cova library docs");
build_docs_step.dependOn(&build_docs.step);
//==========================================
// Examples
//==========================================
const examples = &.{ "cova-demo", "basic_app", "logger" };
var ex_arena: std.heap.ArenaAllocator = .init(b.allocator);
defer ex_arena.deinit();
const ex_alloc = ex_arena.allocator();
inline for (examples) |example| {
var ex_scored_buf = ex_alloc.dupe(u8, example) catch @panic("OOM");
const ex_scored = std.mem.replaceOwned(u8, ex_alloc, ex_scored_buf[0..], "-", "_") catch @panic("OOM");
const ex_name = exName: {
if (std.mem.eql(u8, example, "cova-demo")) break :exName "covademo";
break :exName example;
};
// - Mod
const ex_mod = b.createModule(.{
.root_source_file = b.path(std.fmt.allocPrint(ex_alloc, "examples/{s}.zig", .{ ex_name }) catch @panic("OOM")),
.target = target,
.optimize = optimize,
});
// - Exe
const ex_exe = b.addExecutable(.{
.name = bin_name orelse ex_name,
.root_module = ex_mod,
});
ex_exe.root_module.addImport("cova", cova_mod);
const build_ex_demo = b.addInstallArtifact(ex_exe, .{});
const build_ex_demo_step = b.step(example, "Build the '" ++ example ++ "' example (default: Debug)");
build_ex_demo_step.dependOn(&build_ex_demo.step);
// - Demo Meta Docs
const ex_demo_gen = createDocGenStep(
b,
cova_mod,
b.path("src/generator.zig"),
ex_exe,
.{
.kinds = &.{ .all },
.version = "0.10.2",
.ver_date = "23 OCT 2024",
.author = "00JCIV00",
.copyright = "MIT License",
.help_docs_config = .{
.local_filepath = std.fmt.allocPrint(ex_alloc, "examples/{s}_meta/help_docs/", .{ ex_scored }) catch @panic("OOM"),
},
.tab_complete_config = .{
.local_filepath = std.fmt.allocPrint(ex_alloc,"examples/{s}_meta/tab_completions/", .{ ex_scored }) catch @panic("OOM"),
.include_opts = true,
},
.arg_template_config = .{
.local_filepath = std.fmt.allocPrint(ex_alloc, "examples/{s}_meta/arg_templates/", .{ ex_scored }) catch @panic("OOM"),
},
},
);
const ex_demo_gen_step = b.step(example ++ "-gen", "Generate Meta Docs for the '" ++ example ++ "'");
ex_demo_gen_step.dependOn(&ex_demo_gen.step);
}
}
/// Add Cova's Meta Doc Generation Step to a project's `build.zig`.
/// Note, the `program_step` must have the same Target as the host machine.
/// Prefer to use `addCovaDocGenStepOrError` if the step will be used in cross-compilation CI pipeline.
pub fn addCovaDocGenStep(
b: *std.Build,
/// The Cova Dependency of the project's `build.zig`.
cova_dep: *std.Build.Dependency,
/// The Program Compile Step where the Command Type and Setup Command can be found.
/// This is typically created with `const exe = b.addExecutable(.{...});` or similar
program_step: *std.Build.Step.Compile,
/// The Config for Meta Doc Generation.
doc_gen_config: generate.MetaDocConfig,
) *std.Build.Step.Run {
//const cova_dep = covaDep(b, .{});
return createDocGenStep(
b,
cova_dep.module("cova"),
cova_dep.path("src/generator.zig"),
program_step,
doc_gen_config,
);
}
/// Add Cova's Meta Doc Generation Step to a project's `build.zig` or return an error if there's a Target mismatch.
/// A Target mismatch happens if the provided `program_step` doesn't have the same Target as the host machine.
/// This function is useful for cross-compilation in CI pipelines to ensure Target mismatches are handled properly.
pub fn addCovaDocGenStepOrError(
b: *std.Build,
/// The Cova Dependency of the project's `build.zig`.
cova_dep: *std.Build.Dependency,
/// The Program Compile Step where the Command Type and Setup Command can be found.
/// This is typically created with `const exe = b.addExecutable(.{...});` or similar
program_step: *std.Build.Step.Compile,
/// The Config for Meta Doc Generation.
doc_gen_config: generate.MetaDocConfig,
) !*std.Build.Step.Run {
const host_triplets = b.graph.host.result.zigTriple(b.allocator) catch @panic("OOM");
defer b.allocator.free(host_triplets);
const program_triplets = program_step.rootModuleTarget().zigTriple(b.allocator) catch @panic("OOM");
defer b.allocator.free(program_triplets);
if (!std.mem.eql(u8, host_triplets, program_triplets)) return error.TargetMismatch;
return createDocGenStep(
b,
cova_dep.module("cova"),
cova_dep.path("src/generator.zig"),
program_step,
doc_gen_config,
);
}
/// Create the Meta Doc Generation Step.
fn createDocGenStep(
b: *std.Build,
cova_mod: *std.Build.Module,
cova_gen_path: std.Build.LazyPath,
program_step: *std.Build.Step.Compile,
doc_gen_config: generate.MetaDocConfig,
) *std.Build.Step.Run {
const program_mod = program_step.root_module;
const cova_gen_mod = b.createModule(.{
.root_source_file = cova_gen_path,
.target = b.graph.host,
.optimize = .Debug,
});
const cova_gen_exe = b.addExecutable(.{
.name = std.fmt.allocPrint(b.allocator, "cova_generator_{s}", .{ program_step.name }) catch @panic("OOM"),
.root_module = cova_gen_mod,
});
b.installArtifact(cova_gen_exe);
cova_gen_exe.root_module.addImport("cova", cova_mod);
cova_gen_exe.root_module.addImport("program", program_mod);
const md_conf_opts = b.addOptions();
var sub_conf_map: std.StringHashMapUnmanaged(?*std.Build.Step.Options) = .empty;
defer sub_conf_map.deinit(b.allocator);
sub_conf_map.put(b.allocator, "help_docs_config", null) catch @panic("OOM");
sub_conf_map.put(b.allocator, "tab_complete_config", null) catch @panic("OOM");
sub_conf_map.put(b.allocator, "arg_template_config", null) catch @panic("OOM");
inline for (@typeInfo(generate.MetaDocConfig).@"struct".fields) |field| {
switch(@typeInfo(field.type)) {
.@"struct", .@"enum" => continue,
.optional => |optl| {
switch (@typeInfo(optl.child)) {
.@"struct" => |struct_info| {
const maybe_conf = @field(doc_gen_config, field.name);
if (maybe_conf) |conf| {
const doc_conf_opts = b.addOptions();
inline for (struct_info.fields) |s_field| {
if (@typeInfo(s_field.type) == .@"enum") {
doc_conf_opts.addOption(usize, s_field.name, @intFromEnum(@field(conf, s_field.name)));
continue;
}
doc_conf_opts.addOption(s_field.type, s_field.name, @field(conf, s_field.name));
}
doc_conf_opts.addOption(bool, "provided", true);
sub_conf_map.put(b.allocator, field.name, doc_conf_opts) catch @panic("OOM");
}
continue;
},
else => {},
}
},
.pointer => |ptr| {
if (ptr.child == generate.MetaDocConfig.MetaDocKind) {
var kinds_list: std.ArrayList(usize) = .empty;
defer kinds_list.deinit(b.allocator);
for (@field(doc_gen_config, field.name)) |kind|
kinds_list.append(b.allocator, @intFromEnum(kind)) catch @panic("There was an issue with the Meta Doc Config.");
md_conf_opts.addOption(
[]const usize,
field.name,
kinds_list.toOwnedSlice(b.allocator) catch @panic("There was an issue with the Meta Doc Config."),
);
continue;
}
},
else => {},
}
md_conf_opts.addOption(
field.type,
field.name,
@field(doc_gen_config, field.name),
);
}
cova_gen_exe.root_module.addOptions("md_config_opts", md_conf_opts);
var sub_conf_map_iter = sub_conf_map.iterator();
while (sub_conf_map_iter.next()) |conf| {
cova_gen_exe.root_module.addOptions(
conf.key_ptr.*,
if (conf.value_ptr.*) |conf_opts| conf_opts
else confOpts: {
const conf_opts = b.addOptions();
conf_opts.addOption(bool, "provided", false);
break :confOpts conf_opts;
}
);
}
return b.addRunArtifact(cova_gen_exe);
}
/// Return the Cova Dependency
/// Courtesy of @castholm
fn covaDep(b: *std.Build, args: anytype) *std.Build.Dependency {
getDep: {
const all_pkgs = @import("root").dependencies.packages;
const pkg_hash =
inline for (@typeInfo(all_pkgs).@"struct".decls) |decl| {
const pkg = @field(all_pkgs, decl.name);
if (@hasDecl(pkg, "build_zig") and pkg.build_zig == @This()) break decl.name;
}
else break :getDep;
const dep_name =
for (b.available_deps) |dep| { if (std.mem.eql(u8, dep[1], pkg_hash)) break dep[0]; }
else break :getDep;
return b.dependency(dep_name, args);
}
std.debug.panic("'cova' is not a dependency of '{s}'", .{ b.pathFromRoot("build.zig.zon") });
}
| 11,389 | build | zig | en | zig | code | {"qsc_code_num_words": 1342, "qsc_code_num_chars": 11389.0, "qsc_code_mean_word_length": 4.69299553, "qsc_code_frac_words_unique": 0.19672131, "qsc_code_frac_chars_top_2grams": 0.02159416, "qsc_code_frac_chars_top_3grams": 0.02683392, "qsc_code_frac_chars_top_4grams": 0.00952683, "qsc_code_frac_chars_dupe_5grams": 0.37249921, "qsc_code_frac_chars_dupe_6grams": 0.3137504, "qsc_code_frac_chars_dupe_7grams": 0.26103525, "qsc_code_frac_chars_dupe_8grams": 0.24547475, "qsc_code_frac_chars_dupe_9grams": 0.23499524, "qsc_code_frac_chars_dupe_10grams": 0.23499524, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00282451, "qsc_code_frac_chars_whitespace": 0.28501185, "qsc_code_size_file_byte": 11389.0, "qsc_code_num_lines": 268.0, "qsc_code_num_chars_line_max": 141.0, "qsc_code_num_chars_line_mean": 42.49626866, "qsc_code_frac_chars_alphabet": 0.77060052, "qsc_code_frac_chars_comments": 0.13837914, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.26244344, "qsc_code_cate_autogen": 1.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.08641598, "qsc_code_frac_chars_long_word_length": 0.00957913, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 0 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 1, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
00-Evan/shattered-pixel-dungeon-gdx | core/src/com/shatteredpixel/shatteredpixeldungeon/effects/Wound.java | /*
* Pixel Dungeon
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2019 Evan Debenham
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.effects;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.noosa.Game;
import com.watabou.noosa.Group;
import com.watabou.noosa.Image;
import com.watabou.noosa.Visual;
public class Wound extends Image {
private static final float TIME_TO_FADE = 0.8f;
private float time;
public Wound() {
super( Effects.get( Effects.Type.WOUND ) );
hardlight(1f, 0f, 0f);
origin.set( width / 2, height / 2 );
}
public void reset( int p ) {
revive();
x = (p % Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - width) / 2;
y = (p / Dungeon.level.width()) * DungeonTilemap.SIZE + (DungeonTilemap.SIZE - height) / 2;
time = TIME_TO_FADE;
}
public void reset(Visual v) {
revive();
point(v.center(this));
time = TIME_TO_FADE;
}
@Override
public void update() {
super.update();
if ((time -= Game.elapsed) <= 0) {
kill();
} else {
float p = time / TIME_TO_FADE;
alpha( p );
scale.x = 1 + p;
}
}
public static void hit( Char ch ) {
hit( ch, 0 );
}
public static void hit( Char ch, float angle ) {
if (ch.sprite.parent != null) {
Wound w = (Wound) ch.sprite.parent.recycle(Wound.class);
ch.sprite.parent.bringToFront(w);
w.reset(ch.sprite);
w.angle = angle;
}
}
public static void hit( int pos ) {
hit( pos, 0 );
}
public static void hit( int pos, float angle ) {
Group parent = Dungeon.hero.sprite.parent;
Wound w = (Wound)parent.recycle( Wound.class );
parent.bringToFront( w );
w.reset( pos );
w.angle = angle;
}
}
| 2,517 | Wound | java | en | java | code | {"qsc_code_num_words": 351, "qsc_code_num_chars": 2517.0, "qsc_code_mean_word_length": 4.92307692, "qsc_code_frac_words_unique": 0.42165242, "qsc_code_frac_chars_top_2grams": 0.03645833, "qsc_code_frac_chars_top_3grams": 0.08796296, "qsc_code_frac_chars_top_4grams": 0.04861111, "qsc_code_frac_chars_dupe_5grams": 0.19791667, "qsc_code_frac_chars_dupe_6grams": 0.15277778, "qsc_code_frac_chars_dupe_7grams": 0.0625, "qsc_code_frac_chars_dupe_8grams": 0.0625, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01481481, "qsc_code_frac_chars_whitespace": 0.1954708, "qsc_code_size_file_byte": 2517.0, "qsc_code_num_lines": 97.0, "qsc_code_num_chars_line_max": 94.0, "qsc_code_num_chars_line_mean": 25.94845361, "qsc_code_frac_chars_alphabet": 0.83851852, "qsc_code_frac_chars_comments": 0.31029003, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.1, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0, "qsc_codejava_cate_var_zero": 0.0, "qsc_codejava_frac_lines_func_ratio": 0.11666667, "qsc_codejava_score_lines_no_logic": 0.26666667, "qsc_codejava_frac_words_no_modifier": 0.875, "qsc_codejava_frac_words_legal_var_name": 1.0, "qsc_codejava_frac_words_legal_func_name": 1.0, "qsc_codejava_frac_words_legal_class_name": 1.0, "qsc_codejava_frac_lines_print": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0, "qsc_codejava_cate_var_zero": 0, "qsc_codejava_frac_lines_func_ratio": 0, "qsc_codejava_score_lines_no_logic": 0, "qsc_codejava_frac_lines_print": 0} |
01010111/zerolib | zero/utilities/ECS.hx | package zero.utilities;
/**
* An extremely simple Entity-Component-System implementation!
*
* **Usage:**
*
* - Entities are just integers, but you register and look them up using Strings: `ECS.register_entity('player');`
* - Components are just sets of data tied to an entity: `ECS.register_component('player', 'position', { x: 0, y: 0 });`
* - Systems are classes with an `update()` function that modify data. The update function is fed delta time and an array of entities.
* - In your system's `update()` loop, you can use `ECS.get_data()` to get the relevant data:
* - for example:
* ```
* class MoveRightSystem extends System {
* override public function update(dt:Float, entities:Array<String>) for (entity in entities) {
* var position = ECS.get_data(entity, 'position');
* position.x++;
* }
* }
* ```
* - When you have a System set up, register it and give it a list of necessary components: `ECS.register_system(new MoveRightSystem(), ['position']);`
* - To update all registered systems, use the tick function: `ECS.tick(1/60);`
* - You can also delist entities, components, and systems.
*/
class ECS
{
static var ENTITIES:Map<String, Int> = new Map();
static var COMPONENTS:Map<String, Map<Int, Dynamic>> = new Map();
static var SYSTEMS:Map<System, Array<String>> = new Map();
static var ID_NUMERATOR:Int = 0;
public static function register_entity(name:String)
{
if (ENTITIES.exists(name) || name.length == 0) return error('Entity $name already exists!');
ENTITIES.set(name, ID_NUMERATOR++);
return name;
}
public static function delist_entity(name:String)
{
if (!ENTITIES.exists(name)) return trace('Entity $name does not exist!');
for (cname in COMPONENTS.keys()) delist_component(name, cname);
ENTITIES.remove(name);
}
public static function register_component(entity:String, component:String, data:Dynamic)
{
if (entity.length == 0) return error('Invalid Entity!');
if (!COMPONENTS.exists(component)) COMPONENTS.set(component, []);
COMPONENTS[component].set(ENTITIES[entity], data);
return entity;
}
public static function delist_component(entity:String, component:String)
{
if (!COMPONENTS.exists(component)) return trace('Component $component does not exist!');
if (!ENTITIES.exists(entity)) trace('Entity $entity does not exist!');
if (!COMPONENTS[component].exists(ENTITIES[entity])) return trace('Component $component not found in $entity!');
COMPONENTS[component].remove(ENTITIES[entity]);
}
public static function register_system(system:System, components:Array<String>)
{
SYSTEMS.set(system, components);
}
public static function delist_system(system:System)
{
if (!SYSTEMS.exists(system)) return trace('System ${Type.getClassName(Type.getClass(system))} does not exist!');
SYSTEMS.remove(system);
}
public static function get_entity_id(entity:String):Int
{
if (ENTITIES.exists(entity)) return ENTITIES[entity];
error('Entity $entity does not exist!');
return -1;
}
public static function get_entity_name(entity:Int):String
{
for (name => id in ENTITIES) if (id == entity) return name;
return error('Entity with ID $entity does not exist!');
}
public static function get_entity_data(entity:String):Map<String, Dynamic>
{
if (!ENTITIES.exists(entity)) {
error('Entity $entity does not exist!');
return [];
}
return [ for (name => data in COMPONENTS) if (data.exists(ENTITIES[entity])) name => data[ENTITIES[entity]] ];
}
public static function get_data(entity:String, component:String):Dynamic
{
if (!COMPONENTS.exists(component)) return error('Component $component does not exist!');
if (!ENTITIES.exists(entity)) return error('Entity $entity does not exist!');
if (!COMPONENTS[component].exists(ENTITIES[entity])) return error('No component $component found for entity $entity!');
return COMPONENTS[component][ENTITIES[entity]];
}
public static function tick(dt:Float = 0)
{
var systems = [for (s in SYSTEMS.keys()) s];
systems.sort((s1, s2) -> return s1.priority > s2.priority ? -1 : 1);
for (system in systems) system.update(dt, get_matching_entities(SYSTEMS[system]));
}
static function get_matching_entities(components:Array<String>):Array<String>
{
var out = [];
for (name => id in ENTITIES)
{
var add = true;
for (component in components) if (!COMPONENTS.exists(component) || !COMPONENTS[component].exists(id)) add = false;
if (add) out.push(name);
}
return out;
}
static function error(msg:String):String
{
trace('ERROR: $msg');
return '';
}
}
@:dox(hide)
class System
{
public static var PRIORITY_LAST:Int = -9999999;
public static var PRIORITY_FIRST:Int = 9999999;
public var priority:Int;
public function new(priority:Int = 0) this.priority = priority;
public function update(dt:Float, entities:Array<String>){}
} | 4,855 | ECS | hx | en | haxe | code | {"qsc_code_num_words": 641, "qsc_code_num_chars": 4855.0, "qsc_code_mean_word_length": 5.30733229, "qsc_code_frac_words_unique": 0.19812793, "qsc_code_frac_chars_top_2grams": 0.04585538, "qsc_code_frac_chars_top_3grams": 0.06466784, "qsc_code_frac_chars_top_4grams": 0.02645503, "qsc_code_frac_chars_dupe_5grams": 0.2851264, "qsc_code_frac_chars_dupe_6grams": 0.14609053, "qsc_code_frac_chars_dupe_7grams": 0.14462081, "qsc_code_frac_chars_dupe_8grams": 0.12345679, "qsc_code_frac_chars_dupe_9grams": 0.07231041, "qsc_code_frac_chars_dupe_10grams": 0.04174015, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.00755361, "qsc_code_frac_chars_whitespace": 0.15468589, "qsc_code_size_file_byte": 4855.0, "qsc_code_num_lines": 139.0, "qsc_code_num_chars_line_max": 154.0, "qsc_code_num_chars_line_mean": 34.92805755, "qsc_code_frac_chars_alphabet": 0.82139376, "qsc_code_frac_chars_comments": 0.2315139, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.02, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.12566988, "qsc_code_frac_chars_long_word_length": 0.01152197, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
01010111/zerolib | zero/utilities/Timer.hx | package zero.utilities;
/**
* A Timer that will execute a function once a specified time limit runs out
*
* **Usage**
*
* - Import into your project. `import zero.utilities.Timer;`
* - Create a new timer! `Timer.get(1, () -> trace('hiya world'), 10);` <- traces "hiya world" every 1 second 10 times
* - Make sure to update timers by including this in your game loop: `Timer.update(delta_time);`
* - You can store Timers as variables - `var timer = Timer.get(10, () -> do_thing());`
* - Which will let you pause, unpause, or cancel it - `timer.cancel();`
* - You can cancel all active timers as well - `Timer.cancel_all();`
*/
class Timer {
static var timers:Array<Timer> = [];
static var pool:Array<Timer> = [];
static var epsilon:Float = 1e-8;
public static function get(time:Float, fn:Void -> Void, repeat:Int = 1):Timer {
var timer = pool.length > 0 ? pool.shift() : new Timer();
timer.time = time;
timer.fn = fn;
timer.repeat = repeat;
timer.paused = false;
timer.elapsed = 0;
timers.push(timer);
return timer;
}
public static function update(dt:Float) for (timer in timers) timer.run(dt);
public var paused:Bool;
public var active(get, never):Bool;
function get_active() return timers.indexOf(this) >= 0;
var time:Float;
var elapsed:Float;
var fn:Void -> Void;
var repeat:Int;
function new() {}
public static function cancel_all() for (timer in timers) timer.cancel();
public function reset() elapsed = 0;
public function cancel() if (timers.remove(this)) pool.push(this);
public function pause() paused = true;
public function unpause() paused = false;
public function get_remaining() return time - elapsed;
function run(dt:Float) {
if (paused) return;
elapsed += dt;
if (time - elapsed > epsilon) return;
fn();
elapsed = 0;
repeat--;
if (repeat != 0) return;
cancel();
}
public function toString():String return('time left: ${get_remaining()}');
} | 1,934 | Timer | hx | en | haxe | code | {"qsc_code_num_words": 277, "qsc_code_num_chars": 1934.0, "qsc_code_mean_word_length": 4.67870036, "qsc_code_frac_words_unique": 0.35018051, "qsc_code_frac_chars_top_2grams": 0.06481481, "qsc_code_frac_chars_top_3grams": 0.03240741, "qsc_code_frac_chars_top_4grams": 0.02932099, "qsc_code_frac_chars_dupe_5grams": 0.03240741, "qsc_code_frac_chars_dupe_6grams": 0.0, "qsc_code_frac_chars_dupe_7grams": 0.0, "qsc_code_frac_chars_dupe_8grams": 0.0, "qsc_code_frac_chars_dupe_9grams": 0.0, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.01077313, "qsc_code_frac_chars_whitespace": 0.18407446, "qsc_code_size_file_byte": 1934.0, "qsc_code_num_lines": 65.0, "qsc_code_num_chars_line_max": 119.0, "qsc_code_num_chars_line_mean": 29.75384615, "qsc_code_frac_chars_alphabet": 0.81051965, "qsc_code_frac_chars_comments": 0.31747673, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.0, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.02195307, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
01010111/zerolib | zero/utilities/EventBus.hx | package zero.utilities;
using Std;
/**
* Simple EventBus
*
* **Usage:**
*
* - Assume `MyClass.listener = (?data:Dynamic) -> trace(data.text)`
* - Register listener `EventBus.listen(MyClass.listener, 'hello');`
* - Dispatch data `EventBus.dispatch('hello', { text: 'hello world' });` this will trace: `hello world`
* - Deregister listener when done: `EventBus.unlisten(MyClass.listen, 'hello')`
* - or deregister all listeners: `EventBus.unlisten_all()`
*/
class EventBus
{
static var listeners:Map<String, Array<?Dynamic -> Void>> = [];
static var active_map:Map<String, Bool> = [];
public static function dispatch(name:String, ?data:Dynamic) {
if (!listeners.exists(name)) return;
for (listener in listeners[name]) if (listener != null && active_map[name]) listener(data);
}
public static function listen(listener:?Dynamic -> Void, name:String) {
if (!listeners.exists(name)) listeners.set(name, []);
if (!active_map.exists(name)) active_map.set(name, true);
listeners[name].push(listener);
}
public static function unlisten(listener:?Dynamic -> Void, name:String) {
if (!listeners.exists(name)) return;
listeners[name].remove(listener);
}
public static function unlisten_all() {
for (key in listeners.keys()) listeners.set(key, []);
}
public static function unlisten_signal(name:String) {
listeners.remove(name);
}
public static function set_active(name:String, active:Bool) {
if (!active_map.exists(name)) return;
active_map.set(name, active);
}
} | 1,508 | EventBus | hx | en | haxe | code | {"qsc_code_num_words": 186, "qsc_code_num_chars": 1508.0, "qsc_code_mean_word_length": 5.59139785, "qsc_code_frac_words_unique": 0.29032258, "qsc_code_frac_chars_top_2grams": 0.05192308, "qsc_code_frac_chars_top_3grams": 0.11538462, "qsc_code_frac_chars_top_4grams": 0.06057692, "qsc_code_frac_chars_dupe_5grams": 0.2375, "qsc_code_frac_chars_dupe_6grams": 0.09615385, "qsc_code_frac_chars_dupe_7grams": 0.09615385, "qsc_code_frac_chars_dupe_8grams": 0.09615385, "qsc_code_frac_chars_dupe_9grams": 0.09615385, "qsc_code_frac_chars_dupe_10grams": 0.0, "qsc_code_frac_chars_replacement_symbols": 0.0, "qsc_code_frac_chars_digital": 0.0, "qsc_code_frac_chars_whitespace": 0.14257294, "qsc_code_size_file_byte": 1508.0, "qsc_code_num_lines": 51.0, "qsc_code_num_chars_line_max": 105.0, "qsc_code_num_chars_line_mean": 29.56862745, "qsc_code_frac_chars_alphabet": 0.80433101, "qsc_code_frac_chars_comments": 0.28647215, "qsc_code_cate_xml_start": 0.0, "qsc_code_frac_lines_dupe_lines": 0.06666667, "qsc_code_cate_autogen": 0.0, "qsc_code_frac_lines_long_string": 0.0, "qsc_code_frac_chars_string_length": 0.0, "qsc_code_frac_chars_long_word_length": 0.0, "qsc_code_frac_lines_string_concat": 0.0, "qsc_code_cate_encoded_data": 0.0, "qsc_code_frac_chars_hex_words": 0.0, "qsc_code_frac_lines_prompt_comments": 0.0, "qsc_code_frac_lines_assert": 0.0} | 1 | {"qsc_code_frac_chars_replacement_symbols": 0, "qsc_code_num_words": 0, "qsc_code_num_chars": 0, "qsc_code_mean_word_length": 0, "qsc_code_frac_chars_top_2grams": 0, "qsc_code_frac_chars_top_3grams": 0, "qsc_code_frac_chars_top_4grams": 0, "qsc_code_frac_chars_dupe_5grams": 0, "qsc_code_frac_chars_dupe_6grams": 0, "qsc_code_frac_chars_dupe_7grams": 0, "qsc_code_frac_chars_dupe_8grams": 0, "qsc_code_frac_chars_dupe_9grams": 0, "qsc_code_frac_chars_dupe_10grams": 0, "qsc_code_frac_lines_dupe_lines": 0, "qsc_code_size_file_byte": 0, "qsc_code_num_lines": 0, "qsc_code_num_chars_line_max": 0, "qsc_code_num_chars_line_mean": 0, "qsc_code_frac_chars_alphabet": 0, "qsc_code_frac_chars_digital": 0, "qsc_code_frac_chars_whitespace": 0, "qsc_code_frac_chars_comments": 0, "qsc_code_cate_xml_start": 0, "qsc_code_cate_autogen": 0, "qsc_code_frac_lines_long_string": 0, "qsc_code_frac_chars_string_length": 0, "qsc_code_frac_chars_long_word_length": 0, "qsc_code_cate_encoded_data": 0, "qsc_code_frac_chars_hex_words": 0, "qsc_code_frac_lines_prompt_comments": 0, "qsc_code_frac_lines_assert": 0} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.